Back to programming
programming#python#data-structures

Python Data Structures: Lists, Dicts and Sets

The three collections you'll use every single day — with real examples.

Jane Contributor August 2, 2026 1 views

Python Data Structures

List — an ordered bag

cities = ["Delhi", "Mumbai", "Kolkata"]
cities.append("Chennai")
print(cities[0])           # Delhi
print(cities[-1])          # Chennai (negative index = from the end)
print(len(cities))         # 4

Dict — a lookup table

student = {"name": "Priya", "roll": 42, "cgpa": 8.7}
print(student["name"])     # Priya
student["email"] = "priya@college.edu"

# safer lookup that doesn't crash on missing keys
print(student.get("phone", "N/A"))   # N/A

Set — a bag of unique things

skills = {"python", "sql", "python"}   # duplicate removed
skills.add("docker")
print("python" in skills)              # True (fast!)

When to use which

NeedUse
Ordered items, allow duplicateslist
Look up a value by keydict
Deduplicate + membership checkset

Real-world example

Reading a CSV of college students → a list of dicts is the natural shape:

students = [
    {"name": "Priya", "cgpa": 8.7},
    {"name": "Rahul", "cgpa": 7.9},
]
top = sorted(students, key=lambda s: s["cgpa"], reverse=True)[0]
print(top["name"])   # Priya

Keep reading

You may also like

Discussion (0)

No comments yet. Be the first to weigh in.

Leave a comment

Comments are reviewed before appearing.