Skip to content

Dictionaries · routine

Swap keys and values

Write invert(d) returning a new dictionary where each value of d is a key and each key its value. The values in d are all different. Do not change d.

Run adds print(invert({"a": 1, "b": 2})) after your code, to try it.

Stuck on the idea rather than the code? The Dictionaries lesson walks through it.