Stage 1 · Lesson 6 of 9
Lists, dictionaries and sets
These three collections hold most of the data in a program. keep items in order and allow duplicates, such as scores = [90, 72, 90]. You add to a list with append() and read items by position () or in ranges (slicing).
A maps keys to values, such as {"ada": 90}. It answers "what is the value for this key?" instantly. d["bob"] raises KeyError if the key is missing, while d.get("bob", 0) returns a default instead.
hold unique items in no particular order. A set is the quickest way to remove duplicates or check whether something is present. Choosing between them is the real skill: a list for order, a dictionary for lookup by name, a set for "have I seen this?".
come next: a short way to build a new list from an old one, such as [x * 2 for x in nums].
A question to check yourself, an AI practice session and 4 cheat sheet entries come when you add the roadmap to your account. Add it
Resources for this stage
Start with· follow one of these
- CoursePaidGrokking Python Fundamentals
Design Gurus · Beginner · $50
Beginner Python with an in-browser exercise after nearly every lesson
- CourseFreeCS50's Introduction to Programming with Python
Harvard University · Beginner
Free Harvard course whose weekly problem sets make you write real programs