Learn Lambda Functions by Building an Expense Tracker - Step 18 /help

here is my code, then i will list codes i used but not wroks,(all code used):

def total_expenses(expenses):
    lambda expense: expense['amount']

my code, here above. (orginal with no modifications).

def total_expenses(expenses):
 sum(map(lambda expense: expense['amount'], expenses))

code.

def total_expenses(expenses):
    return sum(map(lambda expense: expense['amount'], expenses))

and other one

map(lambda expense: expense['amount'])

here other code, used:

def total_expenses(expenses): 
    map(lambda expense: expense['amount'],expense)

-i appreciate help, from any one. (no one works).

Hi @zezo-titus

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

You have a typo in the last attempt you posted.

Happy coding

map(lambda expense: expense['amount'], expenses)

Okay, I knew this is the solution, but why in this way? I want to understand.”

map takes a lambda function, and the list to use it on

1 Like