Kodewick
Start learning →
Basic←→0 / 80

Camping gear

#037BasicDictsLoops4 min

You and a friend are going camping and each made a gear list {thing: how many}. Write pack_together(mine, yours) to return the combined list: counts add up when you both bring something, your things first, then the friend's extra ones.

Examples
pack_together({"tent": 1, "torch": 2}, {"torch": 1, "stove": 1})→{'tent': 1, 'torch': 3, 'stove': 1}
pack_together({}, {})→{}
main.py
def pack_together(mine, yours):
    total = dict(mine)
    for thing, n in yours.items():
        # your code here: add the friend's thing into total (starting from 0 if total has none)
        pass
    return total
Ctrl + Enter runs too
Result

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