Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Python Tutorial
  • Interview Questions
  • Python Quiz
  • Python Glossary
  • Python Projects
  • Practice Python
  • Data Science With Python
  • Python Web Dev
  • DSA with Python
  • Python OOPs
Open In App
Next Article:
List of Python GUI Library and Packages
Next article icon

Python DSA Libraries

Last Updated : 13 Dec, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

Data Structures and Algorithms (DSA) serve as the backbone for efficient problem-solving and software development. Python, known for its simplicity and versatility, offers a plethora of libraries and packages that facilitate the implementation of various DSA concepts. In this article, we'll delve into some essential Python libraries for DSA, covering arrays, linked lists, queues, hash maps, heaps, trees, and specialized algorithms like Bisect, Interval Trees, and Trie Trees.

Table of Content

  • Array in Python
  • Linked list in Python
  • Queue in Python
  • Hash Map in Python
  • Heap in Python
  • Tree in Python
  • Bisect Algorithm in Python
  • Interval Tree in Python
  • Trie Tree in Python

Package or Library to Implement Array in Python

Array in Python can be created by importing an array module. array(data_type, value_list) is used to create an array with data type and value list specified in its arguments. 

Package or Library to implement Array in Python

The 'array library' in Python is used to implement Arrays in Python

What is an 'array module' in Python?

An array module in Python defines an object type that can compactly represent an array of basic values: characters, integers, and floating-point numbers.

Important Methods in Array library

  • array.itemsize()
  • array.buffer_info()
  • array.count(x)
  • array.extend(iterable)

Syntax to use Array Library in Python:

# Importing array module
import array as <module variable>
# Creating an array in Python using Array Module
<array variable> = <module variable>.array('<data type of elements>', <list of elements of specified type>)

Example to use Array Library in Python

Python
import array  # Create an array of integers int_array = array.array('i', [1, 2, 3, 4, 5])  # Access elements print(int_array[0]) 

Output
1

Package or Library to Implement Linked list in Python

Linked List consists of a sequence of elements called nodes, where each node contains some data and a reference (or pointer) to the next node in the sequence. The last node typically points to null to indicate the end of the list.

Package or Library to implement Array in Python

The 'collections.deque library' in Python is used to implement Linked list in Python.

What is 'deque module' in Python?

In Python, the collections module provides a versatile deque class, which stands for "double-ended queue". Although it's not specifically named as a "double linked list", it internally uses a doubly linked list structure to provide efficient insertion and deletion operations at both ends of the queue.

Important Methods in deque library

  • append(ele): Add ele to the right side of the deque
  • appendleft(ele): Add ele to the left side of the deque.
  • clear():Remove all elements from the deque leaving it with length 0.
  • copy(): Create a shallow copy of the deque.
  • count(ele): Count the number of deque elements equal to x.
  • extend(): Extend the right side of the deque by appending elements from the iterable argument.
  • extendleft(): Extend the left side of the deque by appending elements from iterable.
  • index(): Return the position of x in the deque. Returns the first match.
  • insert(): Insert x into the deque at position i.
  • pop(): Remove and return an element from the right side of the deque.
  • popleft(): Remove and return an element from the left side of the deque.
  • remove(): Remove the first occurrence of value.
  • reverse(): Reverse the elements of the deque.
  • rotate(): Rotate the deque n steps to the right.

Example to use Deque Library in Python

Python
from collections import deque  # Creating a deque my_queue = deque()  # Adding elements to the queue my_queue.append(1)    # Adds to the right end my_queue.appendleft(2) # Adds to the left end  # Removing elements from the queue element = my_queue.pop()    # Removes and returns from the right end element = my_queue.popleft() # Removes and returns from the left end  # Other methods available in deque include: extend, extendleft, rotate, etc. 

Package or Library to Implement Queue in Python

In a queue, elements are added (enqueue operation) to the rear (also called the "tail") and removed (dequeue operation) from the front (also called the "head"). This ensures that the oldest elements are processed first, while newer elements are added to the end of the queue.

Package or Library to Implement Hash Map in Python

The 'queue.Queue library' in Python is used to implement Queue in Python.

What is 'Queue module' in Python?

In Python, the queue module provides various classes that implement multi-producer, multi-consumer queues. These classes are designed for use in multi-threaded programming and are especially useful for communication between threads safely.

Important Methods in Counter library

  • Queue.qsize(): Return the approximate size of the queue.
  • Queue.empty(): Return True if the queue is empty, False otherwise.
  • Queue.full(): Return True if the queue is full, False otherwise.
  • Queue.put(): Put item into the queue.
  • Queue.get(): Remove and return an item from the queue.

Example to use Queue Library in Python

Python
from queue import Queue  # Creating a queue my_queue = Queue()  # Adding elements to the queue my_queue.put(1) my_queue.put(2) my_queue.put(3)  # Removing elements from the queue # Removes and returns the first element added (FIFO) element = my_queue.get()   print(element)   # Checking if the queue is empty print(my_queue.empty())    # Getting the size of the queue print(my_queue.qsize())    # Other methods available in Queue include: empty, # qsize, full, task_done, join, etc. 

Output

1
False
2

Package or Library to Implement Hash Map in Python

A hash map, also known as a hash table, is a data structure that stores key-value pairs. It provides efficient insertion, deletion, and lookup operations. Hash maps work by using a hash function to map keys to indices in an array.

Package or Library to implement Hash Map in Python

The 'collections.Counter library' in Python is used to implement Hash Map in Python.

What is 'Counter Module' in Python?

A Counter in Python's collections module is a specialized dictionary designed for counting hashable objects. It's particularly useful for counting the occurrences of elements in a collection (e.g., a list or a string). The Counter class provides methods for counting elements efficiently and performing operations like addition, subtraction, intersection, and union of counts.

Important Methods in Counter Library

Certainly! Here are some of the key methods provided by Counter objects in Python's collections module, along with explanations for each:

  1. Counter.elements(): Returns an iterator over elements repeating each as many times as its count. The elements are returned in arbitrary order.
  2. Counter.most_common([n]): Returns a list of the n most common elements and their counts from the most common to the least. If n is omitted or None, returns all elements in the counter.
  3. Counter.subtract([iterable-or-mapping]): Elements are subtracted from an iterable or from another mapping (or counter).
  4. Counter.total(): Compute the sum of the counts.
  5. Counter.update([iterable-or-mapping]): Elements are counted from an iterable or added-in from another mapping (or counter).
  6. Counter.fromkeys(iterable, value): Class method that creates a new Counter object from an iterable and initializes each element's count to the specified value.

Example to use Counter Library in Python

Python
from collections import Counter  # Create a Counter object from a list my_list = ['apple', 'banana', 'apple', 'orange', 'apple', 'banana'] my_counter = Counter(my_list)  print(my_counter) 

Output

Counter({'apple': 3, 'banana': 2, 'orange': 1})

Efficient Libraries for Managing Dictionaries

Also there are collections.ChainMap, collections.defaultdict, and collections.OrderedDict Method inside the collection Library. Here, The Counter itself doesn't inherently utilize it, but you might use them together in certain scenarios, depending on your specific requirements.

What is 'ChainMap Library' in Python?

A ChainMap is a class in Python's collections module that provides the ability to link multiple mappings together to create a single view. It allows you to search multiple dictionaries as if they were one.

# Python program to demonstrate ChainMap 
from collections import ChainMap

d1 = {'a': 1, 'b': 2}
d2 = {'c': 3, 'd': 4}
d3 = {'e': 5, 'f': 6}

# Defining the chainmap
c = ChainMap(d1, d2, d3)

What is 'defaultdict Library' in Python?

The defaultdict is another handy class provided by the collections module in Python. It's a subclass of the built-in dict class and provides a convenient way to create dictionaries with default values for keys that haven't been explicitly set.

from collections import defaultdict
# Define a defaultdict with default value 0
my_defaultdict = defaultdict(int)

What is 'OrderedDict Library' in Python?

The OrderedDict is a dictionary subclass provided by the collections module in Python. It's similar to the built-in dict class but with one key difference: it maintains the order of insertion of its keys.

from collections import OrderedDict
my_ordered_dict = OrderedDict()

Package or Library to Implement Heap in Python

A heap is a specialized tree-based data structure that satisfies the heap property. Heaps are commonly implemented as binary trees, specifically binary min-heaps or binary max-heaps.

Package or Library to Implement Hash Map in Python

The 'heapq library' in Python is used to implement Queue in Python.

What is 'heapq module' in Python?

The heapq module in Python provides a collection of heap-based algorithms, specifically functions to implement heaps as regular lists and perform heap operations efficiently. Despite being named "heapq", it doesn't provide a separate heap data structure class. Instead, it offers functions to manipulate regular Python lists as heaps.

Important Methods in Counter library

The heapq module in Python provides functions rather than methods for heap operations. Here are the main functions available in the heapq module:

  • heapify(heap): This function transforms a list into a heap in linear time.
  • heappush(heap, item): This function adds the item to the heap while maintaining the heap property. It inserts the item at the appropriate position within the heap.
  • heappop(heap): This function removes and returns the smallest element from the heap.
  • heappushpop(heap, item): It pushes the item onto the heap and then pops and returns the smallest element from the heap.
  • heapreplace(heap, item): This function first pops and returns the smallest element from the heap before pushing the new item onto the heap.
  • merge(iterables): This function merges multiple sorted inputs (iterables) into a single sorted output (an iterator).
  • nlargest(n, iterable): This function returns the n largest elements from the iterable, sorted in descending order.
  • nsmallest(n, iterable): This function returns the n smallest elements from the iterable, sorted in ascending order.

Example to use Heapq Library in Python

Python
# importing &quot;heapq&quot; to implement heap queue import heapq  # initializing list li = [5, 7, 9, 1, 3]  # using heapify to convert list into heap heapq.heapify(li)  # printing created heap print (&quot;The created heap is : &quot;,(list(li))) 

Output

The created heap is :  [1, 3, 9, 7, 5]

Package to Implement Tree in Python

A tree is a hierarchical data structure consisting of nodes connected by edges. It's a widely used data structure in computer science for organizing data in a hierarchical manner.

Package or Library to Implement Tree in Python

The 'treelib library' in Python is used to implement Queue in Python.

What is 'treelib Module' in Python?

The treelib is a Python library that provides functionality for working with tree structures. It allows you to create, manipulate, traverse, and visualize tree data structures efficiently.

Important Methods in bisect library

  • create_node(tag, node_id=None, parent=None): Creates a new node with the specified tag and optional data. Optionally specifies the node identifier (node_id) and parent node (parent).
  • remove_node(node_id): Removes the node with the specified identifier from the tree.
  • get_node(node_id): Retrieves the node with the specified identifier from the tree.
  • update_node(node_id, tag=None, data=None): Updates the tag and/or data of the node with the specified identifier.
  • contains(node_id): Checks if the tree contains a node with the specified identifier.
  • parent(node_id): Returns the parent node identifier of the node with the specified identifier.
  • children(node_id): Returns a list of identifiers of the children nodes of the node with the specified identifier.
  • depth(node_id): Calculates the depth of the node with the specified identifier in the tree.
  • size(node_id=None): Calculates the size (number of nodes) of the subtree rooted at the node with the specified identifier. If no identifier is provided, calculates the size of the entire tree.
  • height(node_id=None): Calculates the height (maximum depth) of the subtree rooted at the node with the specified identifier. If no identifier is provided, calculates the height of the entire tree.
  • show(line_type="ascii"): Prints a textual representation of the tree

Example to use Bisect Library in Python

Python
from treelib import Node, Tree  # Create a new binary tree tree = Tree()  # Add nodes to the tree tree.create_node(&quot;Root&quot;, &quot;root&quot;)  # Create the root node # Create a left child node tree.create_node(&quot;Left Child&quot;, &quot;left&quot;, parent=&quot;root&quot;)   # Create a right child node tree.create_node(&quot;Right Child&quot;, &quot;right&quot;, parent=&quot;root&quot;)    # Add more nodes to the left child  # Create a left grandchild node tree.create_node(&quot;Left Grandchild&quot;, &quot;left_grand&quot;, parent=&quot;left&quot;)  # Create a right grandchild node tree.create_node(&quot;Right Grandchild&quot;, &quot;right_grand&quot;, parent=&quot;left&quot;)    # Print the tree structure print(&quot;Tree structure:&quot;) tree.show()  # Traverse the tree (pre-order traversal) print(&quot;\nPre-order traversal:&quot;) for node in tree.all_nodes():     print(node.tag)  # Visualize the tree tree.show(line_type=&quot;ascii-em&quot;)  # Visualize the tree using Graphviz (requires Graphviz installed) # tree.show() 

Output

Tree structure:
root
├── left
│ ├── left_grand
│ └── right_grand
└── right
Pre-order traversal:
root
left
left_grand
right_grand
right
root
|-- left
| |-- left_grand
| +-- right_grand
+-- right

Library to Implement Bisect Algorithm in Python

The bisect algorithm, also known as binary search, is a technique used to efficiently find the position where an element should be inserted into a sorted list to maintain the sorted order. It's named after the bisect function provided by the bisect module in Python, which implements this algorithm.

Package or Library to Implement Bisect Algorithm in Python

The 'bisect library' in Python is used to implement Queue in Python.

What is 'bisect Module' in Python?

The bisect module in Python provides functions to efficiently insert elements into sorted lists and find insertion points for new elements while maintaining the sorted order. It's particularly useful when dealing with sorted collections and needing to maintain their order efficiently.

Important Methods in bisect library

As bisect module support additional methods, Please mention all the methods in points with there explanation

  • bisect(list, num, beg, end): This function returns the position in the sorted list.
  • bisect.bisect_left()
  • bisect.bisect_right()
  • bisect.insort_left()
  • bisect.insort_right()
  • bisect.insort()

Example to use Bisect Library in Python

Python
import bisect  # Sorted list sorted_list = [1, 3, 5, 7, 9]  # Element to insert new_element = 6  # Find the insertion point using bisect_left insertion_point = bisect.bisect_left(sorted_list, new_element)  # Insert the element into the sorted list sorted_list.insert(insertion_point, new_element)  print(&quot;Sorted list after insertion:&quot;, sorted_list) print(&quot;New element inserted at index:&quot;, insertion_point) 

Output

Sorted list after insertion: [1, 3, 5, 6, 7, 9]
New element inserted at index: 3

Package to Implement Interval Tree in Python

An interval tree is a data structure used for efficiently storing and querying intervals or ranges. It's a type of binary search tree specifically designed to handle interval queries effectively.

Package or Library to Implement Bisect Algorithm in Python

The 'intervaltree library' in Python is used to implement Queue in Python.

What is 'intervaltree Module' in Python?

The intervaltree library in Python is a data structure designed to efficiently store and query intervals or ranges. It provides an implementation of an interval tree, a type of binary search tree optimized for interval queries.

Important Methods in intervaltree library

The intervaltree module in Python provides several methods for efficiently working with interval trees.

  • add(interval): Adds an interval to the interval tree.
  • remove(interval): Removes an interval from the interval tree.
  • search(begin): Searches for intervals that overlap with the given range defined by begin and end (inclusive).
  • overlap(begin): Alias for search(). Searches for intervals that overlap with the given range defined by begin and end.
  • at(begin): Searches for intervals that contain the specified point begin. Returns a set of intervals that contain the point.
  • clear(): Clears all intervals from the interval tree, making it empty.
  • copy(): Creates a shallow copy of the interval tree, including all intervals.
  • discard(interval): Removes an interval from the interval tree if it exists, similar to the remove() method.
  • items(): Returns a generator that yields all intervals stored in the interval tree.
  • size(): Returns the number of intervals stored in the interval tree.
  • empty(): Returns True if the interval tree is empty, False otherwise.

Example to use Intervaltree Library in Python

Python
from intervaltree import IntervalTree, Interval  # Create an interval tree tree = IntervalTree()  # Add intervals to the tree tree.add(Interval(1, 5)) tree.add(Interval(3, 8)) tree.add(Interval(6, 10)) tree.add(Interval(12, 15))  # Query intervals that overlap with a given range query_range = (4, 7) result_intervals = tree.search(*query_range)  print(&quot;Intervals that overlap with the query range:&quot;, result_intervals)  # Iterate over the result intervals and print their start and end points print(&quot;Start and end points of the overlapping intervals:&quot;) for interval in result_intervals:     print(&quot;Start:&quot;, interval.begin, &quot;End:&quot;, interval.end) 

Output

Intervals that overlap with the query range: {Interval(1, 5), Interval(3, 8), Interval(6, 10)}
Start and end points of the overlapping intervals:
Start: 1 End: 5
Start: 3 End: 8
Start: 6 End: 10

Package to Implement Trie Tree in Python

A Trie, also known as a prefix tree or digital tree, is a tree-like data structure used to store a dynamic set of strings where the keys are usually strings. Each node in a Trie represents a single character of a string, and the path from the root to a particular node represents a prefix of one or more strings.

Package or Library to Implement Trie in Python

The 'trie library' in Python is used to implement Queue in Python.

What is 'intervaltree Module' in Python?

The intervaltree library in Python is a data structure designed to efficiently store and query intervals or ranges. It provides an implementation of an interval tree, a type of binary search tree optimized for interval queries.

Important Methods in intervaltree library

  • Trie(): Constructor method to create a new Trie object.
  • insert(str) -> None: Inserts a word into the trie.
  • search(str): Searches for a word in the trie. Returns True if the word is found, otherwise False.
  • startswith(prefix: str): Checks if any word in the trie starts with the given prefix. Returns True if a word starts with the prefix, otherwise False.
  • delete(word: str): Deletes a word from the trie.
  • words(prefix: str = ''): Returns a list .of words in the trie that start with the given prefix.

Example to use Trie Library in Python

Python
from trie import Trie  # Create a new Trie object trie = Trie()  # Insert some words into the trie trie.insert(&quot;apple&quot;) trie.insert(&quot;banana&quot;) trie.insert(&quot;app&quot;) trie.insert(&quot;bat&quot;) trie.insert(&quot;ball&quot;)  # Search for words in the trie print(&quot;Search Results:&quot;) print(&quot;Does 'apple' exist?&quot;, trie.search(&quot;apple&quot;))  # Output: True print(&quot;Does 'app' exist?&quot;, trie.search(&quot;app&quot;))      # Output: True print(&quot;Does 'orange' exist?&quot;, trie.search(&quot;orange&quot;))  # Output: False  # Check if any word starts with a given prefix print(&quot;\nStartsWith Results:&quot;) print(&quot;Does any word start with 'ap'?&quot;, trie.startswith(&quot;ap&quot;))  # Output: True print(&quot;Does any word start with 'ora'?&quot;, trie.startswith(&quot;ora&quot;))  # Output: False  # Get autocomplete suggestions for a given prefix print(&quot;\nAutocomplete Suggestions for 'ba':&quot;, trie.autocomplete(&quot;ba&quot;))  # Output: ['ball', 'banana', 'bat']  # Delete a word from the trie trie.delete(&quot;apple&quot;) print(&quot;\nAfter deleting 'apple':&quot;, trie.words())  # Output: ['app', 'ball', 'banana', 'bat']  # Count the total number of words in the trie print(&quot;\nTotal Number of Words:&quot;, trie.count_words())  # Output: 4  # Count the number of words with a given prefix print(&quot;Number of words with prefix 'ba':&quot;, trie.count_prefixes(&quot;ba&quot;))  # Output: 3 


Related Article: Python Data Structures and Algorithms


Next Article
List of Python GUI Library and Packages

S

surajkr_gupta
Improve
Article Tags :
  • Python
  • Python-Library
  • python-modules
  • Python-DSA
Practice Tags :
  • python

Similar Reads

  • Python Tutorial | Learn Python Programming Language
    Python Tutorial – Python is one of the most popular programming languages. It’s simple to use, packed with features and supported by a wide range of libraries and frameworks. Its clean syntax makes it beginner-friendly. Python is: A high-level language, used in web development, data science, automat
    10 min read
  • Python Fundamentals

    • Python Introduction
      Python was created by Guido van Rossum in 1991 and further developed by the Python Software Foundation. It was designed with focus on code readability and its syntax allows us to express concepts in fewer lines of code. Key Features of PythonPython’s simple and readable syntax makes it beginner-frie
      3 min read

    • Input and Output in Python
      Understanding input and output operations is fundamental to Python programming. With the print() function, we can display output in various formats, while the input() function enables interaction with users by gathering input during program execution. Taking input in PythonPython input() function is
      8 min read

    • Python Variables
      In Python, variables are used to store data that can be referenced and manipulated during program execution. A variable is essentially a name that is assigned to a value. Unlike many other programming languages, Python variables do not require explicit declaration of type. The type of the variable i
      7 min read

    • Python Operators
      In Python programming, Operators in general are used to perform operations on values and variables. These are standard symbols used for logical and arithmetic operations. In this article, we will look into different types of Python operators. OPERATORS: These are the special symbols. Eg- + , * , /,
      6 min read

    • Python Keywords
      Keywords in Python are reserved words that have special meanings and serve specific purposes in the language syntax. Python keywords cannot be used as the names of variables, functions, and classes or any other identifier. List of Keywords in PythonTrueFalseNoneandornotisifelseelifforwhilebreakconti
      12 min read

    • Python Data Types
      Python Data types are the classification or categorization of data items. It represents the kind of value that tells what operations can be performed on a particular data. Since everything is an object in Python programming, Python data types are classes and variables are instances (objects) of thes
      10 min read

    • Conditional Statements in Python
      Conditional statements in Python are used to execute certain blocks of code based on specific conditions. These statements help control the flow of a program, making it behave differently in different situations. If Conditional Statement in PythonIf statement is the simplest form of a conditional st
      6 min read

    • Loops in Python - For, While and Nested Loops
      Loops in Python are used to repeat actions efficiently. The main types are For loops (counting through items) and While loops (based on conditions). Additionally, Nested Loops allow looping within loops for more complex tasks. While all the ways provide similar basic functionality, they differ in th
      10 min read

    Python Functions

    • Python def Keyword
      Python def keyword is used to define a function, it is placed before a function name that is provided by the user to create a user-defined function. In Python, a function is a logical unit of code containing a sequence of statements indented under a name given using the “def” keyword. In Python def
      6 min read

    • Python return statement
      A return statement is used to end the execution of the function call and it "returns" the value of the expression following the return keyword to the caller. The statements after the return statements are not executed. If the return statement is without any expression, then the special value None is
      4 min read

    • Global and Local Variables in Python
      Python Global variables are those which are not defined inside any function and have a global scope whereas Python local variables are those which are defined inside a function and their scope is limited to that function only. In other words, we can say that local variables are accessible only insid
      7 min read

    • Recursion in Python
      Recursion involves a function calling itself directly or indirectly to solve a problem by breaking it down into simpler and more manageable parts. In Python, recursion is widely used for tasks that can be divided into identical subtasks. In Python, a recursive function is defined like any other func
      6 min read

    • *args and **kwargs in Python
      In Python, *args and **kwargs are used to allow functions to accept an arbitrary number of arguments. These features provide great flexibility when designing functions that need to handle a varying number of inputs. Example: [GFGTABS] Python # *args example def fun(*args): return sum(args) print(fun
      4 min read

    • Python Lambda Functions
      Python Lambda Functions are anonymous functions means that the function is without a name. As we already know the def keyword is used to define a normal function in Python. Similarly, the lambda keyword is used to define an anonymous function in Python. In the example, we defined a lambda function(u
      7 min read

    • Python map() function
      The map() function is used to apply a given function to every item of an iterable, such as a list or tuple, and returns a map object (which is an iterator). Let's start with a simple example of using map() to convert a list of strings into a list of integers. [GFGTABS] Python s = ['1', '
      4 min read

    Python Data Structures

    • Python String
      A string is a sequence of characters. Python treats anything inside quotes as a string. This includes letters, numbers, and symbols. Python has no character data type so single character is a string of length 1. [GFGTABS] Python s = "GfG" print(s[1]) # access 2nd char s1 = s + s[0] # updat
      6 min read

    • Python Lists
      In Python, a list is a built-in dynamic sized array (automatically grows and shrinks). We can store all types of items (including another list) in a list. A list may contain mixed type of items, this is possible because a list mainly stores references at contiguous locations and actual items maybe s
      6 min read

    • Python Tuples
      A tuple in Python is an immutable ordered collection of elements. Tuples are similar to lists, but unlike lists, they cannot be changed after their creation (i.e., they are immutable). Tuples can hold elements of different data types. The main characteristics of tuples are being ordered , heterogene
      7 min read

    • Dictionaries in Python
      A Python dictionary is a data structure that stores the value in key: value pairs. Values in a dictionary can be of any data type and can be duplicated, whereas keys can't be repeated and must be immutable. Example: Here, The data is stored in key:value pairs in dictionaries, which makes it easier t
      5 min read

    • Python Sets
      Python set is an unordered collection of multiple items having different datatypes. In Python, sets are mutable, unindexed and do not contain duplicates. The order of elements in a set is not preserved and can change. Creating a Set in PythonIn Python, the most basic and efficient method for creatin
      11 min read

    • Python Arrays
      Lists in Python are the most flexible and commonly used data structure for sequential storage. They are similar to arrays in other languages but with several key differences: Dynamic Typing: Python lists can hold elements of different types in the same list. We can have an integer, a string and even
      10 min read

    • List Comprehension in Python
      List comprehension is a way to create lists using a concise syntax. It allows us to generate a new list by applying an expression to each item in an existing iterable (such as a list or range). This helps us to write cleaner, more readable code compared to traditional looping techniques. For example
      4 min read

  • Python OOPs Concepts
    Object Oriented Programming is a fundamental concept in Python, empowering developers to build modular, maintainable, and scalable applications. By understanding the core OOP principles (classes, objects, inheritance, encapsulation, polymorphism, and abstraction), programmers can leverage the full p
    11 min read
  • Python Exception Handling
    Python Exception Handling handles errors that occur during the execution of a program. Exception handling allows to respond to the error, instead of crashing the running program. It enables you to catch and manage errors, making your code more robust and user-friendly. Let's look at an example: Hand
    7 min read
  • File Handling in Python
    File handling refers to the process of performing operations on a file such as creating, opening, reading, writing and closing it, through a programming interface. It involves managing the data flow between the program and the file system on the storage device, ensuring that data is handled safely a
    7 min read
  • Python Database Handling

    • Python MongoDB Tutorial
      MongoDB is one of the most popular NoSQL database. It is a cross-platform, object-oriented database. Basically NoSQL means MongoDB does not store data in the table or relational format rather provide a different mechanism for storage and retrieval of data. This is called BSON which is similar to JSO
      3 min read

    • Python MySQL
      Python MySQL Connector is a Python driver that helps to integrate Python and MySQL. This Python MySQL library allows the conversion between Python and MySQL data types. MySQL Connector API is implemented using pure Python and does not require any third-party library.  This Python MySQL tutorial will
      9 min read

    Python Packages or Libraries

    • Python Modules
      Python Module is a file that contains built-in functions, classes,its and variables. There are many Python modules, each with its specific work. In this article, we will cover all about Python modules, such as How to create our own simple module, Import Python modules, From statements in Python, we
      7 min read

    • Python DSA Libraries
      Data Structures and Algorithms (DSA) serve as the backbone for efficient problem-solving and software development. Python, known for its simplicity and versatility, offers a plethora of libraries and packages that facilitate the implementation of various DSA concepts. In this article, we'll delve in
      15+ min read

    • List of Python GUI Library and Packages
      Graphical User Interfaces (GUIs) play a pivotal role in enhancing user interaction and experience. Python, known for its simplicity and versatility, has evolved into a prominent choice for building GUI applications. With the advent of Python 3, developers have been equipped with lots of tools and li
      12 min read

    Data Science with Python

    • Python NumPy
      Numpy is a general-purpose array-processing package. It provides a high-performance multidimensional array object, and tools for working with these arrays. It is the fundamental package for scientific computing with Python. Besides its obvious scientific uses, Numpy can also be used as an efficient
      6 min read

    • Pandas Tutorial
      Pandas is an open-source software library designed for data manipulation and analysis. It provides data structures like series and DataFrames to easily clean, transform and analyze large datasets and integrates with other Python libraries, such as NumPy and Matplotlib. It offers functions for data t
      7 min read

    • Matplotlib Tutorial
      Matplotlib is an open-source visualization library for the Python programming language, widely used for creating static, animated and interactive plots. It provides an object-oriented API for embedding plots into applications using general-purpose GUI toolkits like Tkinter, Qt, GTK and wxPython. It
      5 min read

    • Introduction to Seaborn - Python
      Prerequisite - Matplotlib Library  Visualization is an important part of storytelling, we can gain a lot of information from data by simply just plotting the features of data. Python provides a numerous number of libraries for data visualization, we have already seen the Matplotlib library in this a
      5 min read

    • StatsModel Library- Tutorial
      Statsmodels is a useful Python library for doing statistics and hypothesis testing. It provides tools for fitting various statistical models, performing tests and analyzing data. It is especially used for tasks in data science ,economics and other fields where understanding data is important. It is
      4 min read

    • Learning Model Building in Scikit-learn
      Building machine learning models from scratch can be complex and time-consuming. However with the right tools and frameworks this process can become significantly easier. Scikit-learn is one such tool that makes machine learning model creation easy. It provides user-friendly tools for tasks like Cla
      10 min read

    • XGBoost
      Traditional machine learning models like decision trees and random forests are easy to interpret but often struggle with accuracy on complex datasets. XGBoost, short for eXtreme Gradient Boosting, is an advanced machine learning algorithm designed for efficiency, speed, and high performance. What is
      9 min read

    • TensorFlow Tutorial
      TensorFlow is an open-source machine-learning framework developed by Google. It is written in Python, making it accessible and easy to understand. It is designed to build and train machine learning (ML) and deep learning models. It is highly scalable for both research and production.It supports CPUs
      3 min read

    • What is PyTorch ?
      PyTorch is a deep learning library built on Python and Torch (a Lua-based framework). It provides GPU acceleration, dynamic computation graphs, and an intuitive interface for deep learning researchers and developers. PyTorch follows a "define-by-run" approach, meaning that its computational graphs a
      5 min read

geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences