Back to Freecodecamp

Step 26

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

latest1.3 KB
Original Source

--description--

Now, call map() passing your lambda function as the first argument and the expenses list as the second argument.

--hints--

You should call the map() function inside the total_expenses function.

js
({ test: () => assert(runPython(`len(_Node(_code).find_function("total_expenses").find_calls("map")) == 1`)) })

You should pass your lambda function as the first argument to the map() call.

js
({ test: () => assert(runPython(`_Node(_code).find_function("total_expenses").find_calls("map")[0].find_call_args()[0].is_equivalent("lambda expense: expense['amount']")`)) })

You should pass the expenses list as the second argument to the map() call.

js
({ test: () => assert(runPython(`_Node(_code).find_function("total_expenses").find_calls("map")[0].find_call_args()[1].is_equivalent("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):
    lambda expense: expense['amount']
--fcc-editable-region--

expenses = []