Learn Lambda Functions by Building an Expense Tracker - Step 18

Tell us what’s happening:

so i tried to do as the assignment says

call map() and pass lambda as first argument and expenses as second. But everytime i try to do so i get an error. So i dont know where i’m going wrong. also tried to maybe put it between “” or ‘’ and even .

but im stuck… pls help

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):
    lambda expense: expense['amount']
    map(lambda , expenses)

# User Editable Region


expenses = []

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36 OPR/112.0.0.0

Challenge Information:

Learn Lambda Functions by Building an Expense Tracker - Step 18

Welcome to the forum @elisa.steel.t

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

  1. pass your lambda function as the first argument ✗
  2. expenses list as the second argument ✓

Please remove the follow code as it not correct.

For this step, the lambda function is the first argument of the map() call.

Happy coding

1 Like

i don’t really understand what you mean by that, if i delete what i have now then i wouldn’t be able to fulfill the assignment

Hi @elisa.steel.t,

Let’s use a similar example:

def game_function(games):
    lambda game: game['type']

So if I want to call map() passing my lambda function as the first argument and the games list as the second argument. I might do something like:

    map(lambda game: game['type'], games)

I hope this helps. Happy coding!

Thank you soo much!!
i’ve finally been able to solve it

1 Like