Internal implementation of Data Structures in Python Last Updated : 08 Sep, 2023 Summarize Comments Improve Suggest changes Share Like Article Like Report Python provides a variety of built-in data structures, each with its own characteristics and internal implementations optimized for specific use cases. In this article we are going to discuss about the most commonly used Data structures in Python and a brief overview of their internal implementations: Data Structure Internal Implementation Static or Dynamic Python List Dynamic Arrays Dynamic Python Tuples Arrays Static Python Sets Hash Tables Dynamic Python Deque Doubly linked list Dynamic Python Dictionary Hash Tables Dynamic Python String Array of Unicode characters Dynamic Python Array Array Static Python HeapQ Binary Trees Dynamic Python Hash maps Hash Functions Dynamic Lists: Lists are ordered collections of items, and their elements can be of different data types. Internally, lists are implemented as dynamic arrays that can grow or shrink as needed. When the array is full, a new larger array is created, and elements are copied over. This resizing operation is amortized, meaning it doesn't happen every time an element is added.Tuples: Tuples are similar to lists but are immutable, meaning their elements cannot be changed after creation. Internally, tuples are usually implemented as fixed-size arrays, and their immutability allows for some memory optimization and better performance in certain scenarios.Sets: Sets are unordered collections of unique elements. Internally, sets are implemented using hash tables. Each element is hashed, and the hash value is used to quickly locate the element within the table.Dictionaries: Dictionaries (dicts) are collections of key-value pairs, where keys are unique and immutable. Dicts are implemented using hash tables as well. Keys are hashed to determine their position in the table, and values are associated with these keys.Strings: Strings are sequences of characters. Internally, Python strings are usually implemented as arrays of Unicode characters. The specific implementation details can vary depending on factors like Python version and compilation options.Arrays: Python provides an array module that allows you to create arrays with elements of a specific data type. These arrays are more memory-efficient than lists when dealing with large quantities of homogeneous data.Heap: Python's heapq module provides heap-related functions. Heaps are binary trees that satisfy the heap property (parent nodes are smaller or larger than their children).Collections from the collections module: This module provides specialized data structures like defaultdict, Counter, OrderedDict, and deque. They offer optimized implementations for specific use cases, such as default values, counting elements, ordered insertion, and double-ended queues.Hash Maps: Also known as hash tables or associative arrays. Similar to dictionaries in Python, they store key-value pairs and offer fast access to values based on their keys. Internally, they use a hash function to convert keys into indices in an array, allowing for efficient lookups.Graphs: Graphs consist of nodes (vertices) and edges connecting these nodes. They can be implemented using various structures, such as adjacency matrices (2D arrays) or adjacency lists (lists of linked nodes). Graphs are used to model relationships between entities.Remember that the exact internal implementation details might vary between Python versions and implementations (like CPython, Jython, IronPython, etc.). The Python language abstracts these implementation details and provides a consistent interface for developers to work with these data structures. Comment More infoAdvertise with us Next Article Introduction to Data Structures P paras_tiwari_gfg Follow Improve Article Tags : DSA Similar Reads Implementation of Hash Table in Python using Separate Chaining A hash table is a data structure that allows for quick insertion, deletion, and retrieval of data. It works by using a hash function to map a key to an index in an array. In this article, we will implement a hash table in Python using separate chaining to handle collisions. Components of hashing Sep 7 min read Introduction to Data Structures What is Data Structure?A data structure is a particular way of organising data in a computer so that it can be used effectively. The idea is to reduce the space and time complexities of different tasks. The choice of a good data structure makes it possible to perform a variety of critical operations 7 min read Learn DSA with Python | Python Data Structures and Algorithms This tutorial is a beginner-friendly guide for learning data structures and algorithms using Python. In this article, we will discuss the in-built data structures such as lists, tuples, dictionaries, etc. and some user-defined data structures such as linked lists, trees, graphs, etc.1. ListList is a 8 min read What Should I Learn First: Data Structures or Algorithms? Data structure and algorithms are an integral part of computer science. All the enthusiasts, at some point in time, learn these two important topics. They are different yet very much interrelated topics. This interrelation brings out the big question that needs to be answered: "What should I learn f 10 min read LMNs-Data Structures Data structures are ways to organize and store data so it can be used efficiently. They are essential in computer science for managing and processing information in programs. Common types of data structures include arrays, linked lists, stacks, queues, trees, and graphs. Each structure is designed f 14 min read Common operations on various Data Structures Data Structure is the way of storing data in computer's memory so that it can be used easily and efficiently. There are different data-structures used for the storage of data. It can also be defined as a mathematical or logical model of a particular organization of data items. The representation of 15+ min read Like