All challenges

Thursday, 8 October 2026

Past

Three rungs, one idea. Solving rung 1 counts. Climb as far as you can.

Looking Up By Value

dictionaries + swapping around

Rung 1Daily goal5 points

Turn it around

Write a function called swap_pairs

ages is a dictionary of name to age. Return a new dictionary that uses the ages as keys and the names as values, so {"ana": 10} becomes {10: "ana"}. No two people share an age here. An empty dictionary returns an empty dictionary.

Examples

InputOutput
{"ana": 10, "bo": 12}{10: "ana", 12: "bo"}
{}{}
{"cy": 9}{9: "cy"}
{"a": 0}{0: "a"}

There are extra hidden tests, so make it work in general, not just for these.

Rung 2Bonus7 points

Who is that age

Write a function called who_is

Now two people are allowed to share an age. Return the name of the person whose age is age, and if more than one matches, the one that comes first in the dictionary. Return None when nobody is that age and when the dictionary is empty.

Examples

InputOutput
{"ana": 10, "bo": 12}, 12"bo"
{"ana": 10, "bo": 10}, 10"ana"
{}, 10None
{"cy": 9}, 8None

There are extra hidden tests, so make it work in general, not just for these.

Rung 3Bonus10 points

Everybody of each age

Write a function called group_by_age

Turn the dictionary around again, but this time keep everybody. Return a dictionary where each age points to a list of the names of that age, in the order those names appear in the input. So {"ana": 10, "bo": 10} becomes {10: ["ana", "bo"]}. An empty dictionary returns an empty dictionary.

Examples

InputOutput
{"ana": 10, "bo": 12}{10: ["ana"], 12: ["bo"]}
{"ana": 10, "bo": 10}{10: ["ana", "bo"]}
{}{}
{"cy": 9}{9: ["cy"]}

There are extra hidden tests, so make it work in general, not just for these.

Finish Rung 1 and today counts. Rungs 2 and 3 are there if you want to push further.