Kodewick
Start learning →
Mini challenge←→0 / 80

Breakfast orders

#039Mini challengeDictsSorting6 min

The breakfast café logs orders as (name, dish), and some people order the same dish twice. Write who_ordered(orders) to return {dish: [people who ordered it]}: dishes in the order first seen, people listed once each, alphabetically. No orders gives {}.

Examples
who_ordered([("Mia", "pancakes"), ("Leo", "eggs"), ("Mia", "pancakes"), ("Ann", "pancakes")])→{'pancakes': ['Ann', 'Mia'], 'eggs': ['Leo']}
who_ordered([])→{}
main.py
def who_ordered(orders):
    people = {}
    for person, dish in orders:
        # your code here: add the person to this dish's set (giving the dish an empty set first)
        pass
    # your code here: loop again and turn each dish's set into a sorted list
    return people
Ctrl + Enter runs too
Result

Run tries the examples. When they look right, Submit.