Programming foundations

Stage 1 · Lesson 6 of 9

Lists, dictionaries and sets

Your first language

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

Practise

  • Small exercises in your language track, with free feedback from a human mentor

Keep handy

  • The official tour: read the matching chapter after the course covers a topic

  • Quick syntax lookups and an online compiler for testing a snippet on a shared computer

Mark this stage as not done?