Free course · Lesson 4 of 5
Data Structures: Lists, Dicts & Sets
In this lesson you will
- Store records in lists and dictionaries
- Look up values by key
Real programs manage collections of data, not single values. Python's built-in structures cover almost every case: lists for ordered items, dictionaries for labeled data, and sets for unique values.
list: ordered, changeable —students = ["Amina", "Deng", "Grace"]dict: key-value pairs —student = {"name": "Amina", "level": "Beginner"}set: unique, unordered — great for removing duplicate entries.- List comprehensions (
[x for x in items if condition]) filter and transform in one line.
💡 Practical Skill: Model real records as dictionaries inside a list — this is exactly the shape of data you'll later read from a spreadsheet, a database, or a JSON API response.
students = [ {"name": "Amina", "level": "Beginner", "score": 78}, {"name": "Deng", "level": "Intermediate", "score": 91}, {"name": "Grace", "level": "Beginner", "score": 64},] # List comprehension: students who passed (score >= 70)passed = [s["name"] for s in students if s["score"] >= 70]print("Passed:", passed) # Remove duplicate levels using a setlevels_offered = {s["level"] for s in students}print("Levels in this class:", levels_offered)
Practice exercise
Create a price dictionary for five products and let the user look one up, with a friendly message if it is missing.
Key takeaways
- Lists keep items in order; dictionaries look values up by key
- dict.get() avoids errors for missing keys
- A list of dictionaries is the shape of most real data
Free self-study lesson — no certificate. For the full instructor-led program, see registration options.