Dicts and sets
A dict maps keys to values. Lookup by key takes about the same time however large the dict is. Dicts keep insertion order.
ages = {"ada": 36}
ages["alan"] = 41
print(ages.get("bob", 0)) # 0, no error
print("ada" in ages) # True
for k, v in ages.items():
print(k, v)d[key] raises KeyError when the key is missing. d.get(key, default) does not. Keys must be hashable, so strings, numbers and tuples work and lists do not.
Sets
A set holds unique values with no useful order, and it supports membership tests and set algebra.
a = {1, 2, 3}
b = {2, 3, 4}
print(a & b) # intersection
print(a | b) # union
print(a - b) # differenceBecause a set's order is not guaranteed, sort it before showing or comparing it. Write set() for an empty set, since {} is an empty dict.
Your task
Write word_counts(text) returning a dict from lower-cased word to how many times it appears. Write common_items(a, b) returning a sorted list of the values present in both lists, without duplicates.
The explanation opens here once every check passes.