Learn Lambda Functions by Building an Expense Tracker - Step 25

Tell us what’s happening:

What I attempted:
return sum(map(lambda expense: expense[‘amount’], expenses))
This was my line of code under the intended block on the def total expenses. For some reason it says it is wrong. I have also tried:
return lambda expense: expense[‘amount’]
It still says it is wrong. Can one of you please tell me the correct syntax because I am likely to interpret and understand. Also when I get it wrong the hint keeps repeating the instructions instead of telling me the correct syntax.

Your code so far

def add_expense(expenses, amount, category):
    expenses.append({'amount': amount, 'category': category})
    
def print_expenses(expenses):
    for expense in expenses:
        print(f'Amount: {expense["amount"]}, Category: {expense["category"]}')
    

# User Editable Region

def total_expenses(expenses):

    return lambda expense: expense['amount']


# User Editable Region


expenses = []

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.6 Safari/605.1.15

Challenge Information:

Learn Lambda Functions by Building an Expense Tracker - Step 25

Your code is not wrong. Test is not expecting return at that point.

Sorry for the late response but I eventually realized. Thank you!

1 Like