Dictionaries map keys to values for instant lookups; sets store each unique item exactly once.
1 Dict = Key to Value
{"Ada": 36} stores a pair; ages["Ada"] fetches the value in one hop.
2 Keys Are Unique
Writing to an existing key overwrites it; a brand-new key is simply added.
3 in Checks Membership
"Ben" in ages asks if the key exists — sets answer the same question for their items.
4 Sets Deduplicate
{1, 2, 2, 3} collapses to {1, 2, 3} — duplicates are impossible in a set.
Look things up by name
Dict = Key to Value1{"Ada": 36} stores a pair; ages["Ada"] fetches the value in one hop. Keys Are Unique2Writing to an existing key overwrites it; a brand-new key is simply added. in Checks Membership3"Ben" in ages asks if the key exists — sets answer the same question for their items. Sets Deduplicate4{1, 2, 2, 3} collapses to {1, 2, 3} — duplicates are impossible in a set. 4 building blocks make up Look things up by name
Add and overwrite dict keys, then watch a set swallow duplicates without growing.
mainages starts with two key-value pairs — each key maps to one value.
Memory
ages= {'Ada': 36, 'Ben': 19}
Console
output appears as the program runs…
Before reading ages[key], good code asks whether the key exists — follow the two paths.
process decision input / output start / end Click a snippet, then click what it gives you.
5 conceptsTap a card to expand ?{"a": 1}drops into place
?ages["Ada"]drops into place
?"x" in agesdrops into place
?{1, 2, 3}drops into place
?len(d)drops into place
An overwrite and a collapsing set — what survives?
Your predicted output — one line per console line
Hint: Writing to an existing key overwrites it. A set keeps each value once — three identical "pen"s collapse into one.
01A dict maps each key to one value; ages["Ada"] is a one-hop lookup.
02Assigning to a new key adds it; assigning to an existing key overwrites.
03KeyError is what you get for reading a key that was never added.
04Sets keep unique items only — adding a duplicate changes nothing.
05in works on both: keys of a dict, items of a set.