In this tutorial, we will compare lists, tuples, sets, and dictionaries. Python provides several built-in data structures to store collections of data, including lists, tuples, sets, and dictionaries. In this tutorial, we’ll explore the differences between these four fundamental data structures and provide examples of when to use each one.
Lists
A list in Python is an ordered, mutable collection of elements enclosed in square brackets []. Lists can contain elements of different data types, including numbers, strings, and even other lists. Lists are used when you have data you want to further modify or alter, like sorting.
Example:
fruits = ['apple', 'banana', 'orange']
fruits.append('grape')
print(fruits)Output:
['apple', 'banana', 'orange', 'grape']I have excited the above example code and added the screenshot below.

Read Difference Between = and == in Python
Tuples
A tuple is an ordered, immutable collection of elements enclosed in parentheses (). Once created, the elements in a tuple cannot be modified. Tuples are collections of Python objects separated by commas. Tuples are often used to store related pieces of information.
Example:
person = ('John', 25, 'New York')
name, age, city = person
print(name) Output:
JohnI have excited the above example code and added the screenshot below.

Read Difference Between {} and [] in Python
Sets
A set is an unordered collection of unique elements enclosed in curly braces {}. Sets do not allow duplicate values and are useful for removing duplicates from a list or performing mathematical set operations like union, intersection, and difference. Sets have no guaranteed order.
Example:
numbers = {1, 2, 3, 4, 4, 5}
print(numbers) Output:
{1, 2, 3, 4, 5}I have excited the above example code and added the screenshot below.

Read How to Comment Out a Block of Code in Python?
Dictionaries
A dictionary is an unordered collection of key-value pairs enclosed in curly braces {}. Each key in a dictionary must be unique and is used to access its corresponding value. Dictionaries are used when you have two sets of related data.
Example:
student = {'name': 'Alice', 'age': 20, 'major': 'Computer Science'}
print(student['name'])Output:
AliceRead Difference Between “is None” and “== None” in Python
When to Use Each Data Structure
- Use a list when you need an ordered, mutable collection of elements that allows duplicates.
- Use a tuple when you need an ordered, immutable collection of elements. Tuples are more memory-efficient than lists.
- Use a set when you need an unordered collection of unique elements and want to perform set operations.
- Use a dictionary when you need an unordered collection of key-value pairs and want fast lookups by keys.
Comparison Table
| Data Structure | Ordered | Mutable | Allows Duplicates | Lookup Complexity |
|---|---|---|---|---|
| List | Yes | Yes | Yes | O(n) |
| Tuple | Yes | No | Yes | O(n) |
| Set | No | Yes | No | O(1) |
| Dictionary | No | Yes | No (keys) | O(1) |
Read Python 3 vs Python 2 [Key Differences]
Conclusion
In this tutorial, I have explained the differences between lists, tuples, sets, and dictionaries in Python. Lists are versatile and widely used, tuples are immutable and memory-efficient, sets are ideal for dealing with unique elements and set operations and dictionaries provide fast key-value lookups.
You may also like to read:

I am Bijay Kumar, a Microsoft MVP in SharePoint. Apart from SharePoint, I started working on Python, Machine learning, and artificial intelligence for the last 5 years. During this time I got expertise in various Python libraries also like Tkinter, Pandas, NumPy, Turtle, Django, Matplotlib, Tensorflow, Scipy, Scikit-Learn, etc… for various clients in the United States, Canada, the United Kingdom, Australia, New Zealand, etc. Check out my profile.