πŸš€ Day 9 of My Python Learning Journey



This content originally appeared on DEV Community and was authored by Aditi Sharma

Understanding the Differences Between List, Tuple, Set, and Dictionary

After completing Python’s core data structures, I decided to summarize the main differences between them. These are the building blocks of Python, and knowing when to use each makes a big difference in writing clean & efficient code.

🔹 1. List
β€’ Ordered
β€’ Mutable (can change after creation)
β€’ Allows duplicates
β€’ Best for collections that need modification

my_list = [1, 2, 2, 3]
my_list.append(4)
print(my_list) # [1, 2, 2, 3, 4]

🔹 2. Tuple
β€’ Ordered
β€’ Immutable (cannot be changed after creation)
β€’ Allows duplicates
β€’ Best for fixed collections (e.g., coordinates, settings)

my_tuple = (1, 2, 3)
print(my_tuple[0]) # 1

🔹 3. Set
β€’ Unordered
β€’ Mutable (can add/remove items)
β€’ No duplicates
β€’ Best for uniqueness, filtering, and set operations

my_set = {1, 2, 2, 3}
print(my_set) # {1, 2, 3}

🔹 4. Dictionary
β€’ Unordered (Python 3.7+ keeps insertion order)
β€’ Mutable
β€’ Key-Value pairs
β€’ Keys must be unique, values can repeat
β€’ Best for fast lookups and mappings

my_dict = {“name”: “Alice”, “age”: 25}
print(my_dict[“name”]) # Alice

Feature List Tuple Set Dictionary
Ordered ✅ ✅ ❌ ✅ (insertion order)
Mutable ✅ ❌ ✅ ✅
Duplicates ✅ ✅ ❌ Keys ❌, Values ✅
Use Case Dynamic collection Fixed collection Unique items Key-value mapping

✨ Reflection
Understanding these four data structures has given me a strong foundation in Python. Now I can choose the right structure for the right problem, which is crucial in data analytics and real-world programming.

Next up β†’ I’ll start exploring Python libraries that make coding even more powerful. 🚀

Python #DataStructures #100DaysOfCode #DevCommunity #LearningJourney


This content originally appeared on DEV Community and was authored by Aditi Sharma