Kodewick
Start learning →
Basic←→0 / 80

Trip spending

#076BasicStringsDicts5 min

The trip's spending has one entry per line: a category and an amount, like "food 30". Write biggest_spend(text): add up each category and return the one with the most spent. With no entries, return None (already in the starter). No two categories tie.

Examples
biggest_spend("food 30\nbus 12\nfood 25\nhotel 50")→'food'
biggest_spend("")→None
main.py
def biggest_spend(text):
    if text == "":
        return None
    spent = {}
    for line in text.splitlines():
        kind, money = line.split()
        # your code here: add this amount to its category's total
    # your code here: return the category with the biggest total
    return None
Ctrl + Enter runs too
Result

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