Back to Freecodecamp

Step 27

curriculum/challenges/english/blocks/learn-lambda-functions-by-building-an-expense-tracker/65823dde36392f505a39f7c7.md

latest898 B
Original Source

--description--

Finally, pass your map() call to the sum() function to obtain the total expenses and return the result.

--hints--

You should call the sum() function passing it your current map() call as the argument and return the result from your total_expenses function.

js
({ test: () => assert(runPython(`_Node(_code).find_function("total_expenses").has_return("sum(map(lambda expense: expense['amount'], expenses))")`)) })

--seed--

--seed-contents--

py
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"]}')
    
--fcc-editable-region--
def total_expenses(expenses):
    map(lambda expense: expense['amount'], expenses)
--fcc-editable-region--

expenses = []