Challenge
PastOne concept, three rungs. Reaching rung 1 is the goal, so climb as far as you can.
Sticker Counts
simple dictionaries + looping
All the stickers
Write a function called total_stickers
You get a dictionary where each name points to how many stickers that child has, like {"amy": 3, "bob": 2}. Add up all the sticker counts and return the total. An empty dictionary gives 0.
Examples
| Input | Output |
|---|---|
| {"amy": 3, "bob": 2} | 5 |
| {} | 0 |
| {"amy": 0} | 0 |
| {"amy": 10} | 10 |
There are extra hidden tests, so make it work in general, not just for these.
Who has the most
Write a function called who_has_most
Return the name of the child with the most stickers. If two children have the same amount, return the one that comes first in the dictionary. An empty dictionary returns None.
Examples
| Input | Output |
|---|---|
| {"amy": 3, "bob": 5} | "bob" |
| {} | None |
| {"amy": 1} | "amy" |
| {"amy": 2, "bob": 2} | "amy" |
There are extra hidden tests, so make it work in general, not just for these.
Enough stickers
Write a function called at_least
Return a list of the names that have n stickers or more, keeping the order they appear in the dictionary. If nobody has that many, return an empty list.
Examples
| Input | Output |
|---|---|
| {"amy": 3, "bob": 1}, 2 | ["amy"] |
| {}, 1 | [] |
| {"amy": 5}, 5 | ["amy"] |
| {"amy": 1, "bob": 2}, 9 | [] |
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.