![]() |
Python offers several built-in data structures that allow you to manage, organize, and manipulate data efficiently. Understanding data structures is essential for writing optimized, performant code.
List of data structures
List: ordered and mutable collections (can be modified after their creation and maintain their insertion order).
Tuple: similar to lists, but immutable (cannot be modified after creation).
Dictionary: unordered collections of key-value pairs (as of Python 3.7, they preserve insertion order, but do not allow duplicate keys).
Set: collections of unique, unordered items (do not retain insertion order and do not allow duplicates).
Queue: FIFO (First In, First Out) data structures, where the first element inserted is the first to be removed.
Stack: LIFO (Last In, First Out) data structures, where the last element inserted is the first to be removed.
Below, we will analyze each of these structures in detail with practical examples.
1. List
Lists in Python are ordered, mutable collections that can contain elements of different types. "Ordered" means that the order of the elements remains unchanged, while "mutable" means that elements can be added, removed, or modified.
Example
2. Tuple
Tuples are similar to lists, but they are immutable. "Immutable" means that once a tuple is created, it cannot be modified (you cannot add, remove, or change elements).
Example
3. Dictionary
Dictionaries are unordered, mutable collections of key-value pairs. However, starting with Python 3.7, the insertion order is preserved. Each key is unique, allowing quick access to its corresponding values.
Example
4. Set
Sets are unordered, mutable collections of unique elements. "Unordered" means that the elements have no fixed order, while "mutable" means that elements can be added or removed. Also, "unique" means that there can be no duplicates.
Example
5. Queue
Queues are FIFO (First In, First Out) data structures, meaning the first item added is the first item removed. Python provides the queue module to manage them efficiently.
Example
6. Stack
Stacks follow the LIFO (Last In, First Out) logic, where the last element inserted is the first to be removed. They can be implemented with lists or with queue.LifoQueue.
Example
Summary table
![]() |
Follow me #techelopment
Official site: www.techelopment.it
facebook: Techelopment
instagram: @techelopment
X: techelopment
Bluesky: @techelopment
telegram: @techelopment_channel
whatsapp: Techelopment
youtube: @techelopment