Learn Lambda Functions by Building an Expense Tracker - Step 25

Tell us what’s happening:

what in the big blue sea am I missing to do in this step? because I have no idea what I’m missing

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 arguments: expense
    return expense["amount"]

# 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/133.0.0.0 Safari/537.36

Challenge Information:

Learn Lambda Functions by Building an Expense Tracker - Step 25

Getting there. The instructions do not ask you to return anything.

return expense["amount"]

This is how you access the “amount” key in the expense dictionary, so that’s good :+1:

Example of lambda syntax: https://www.w3schools.com/python/python_lambda.asp

lambda arguments : expression

Arguments and parameters go together, right?

Replace pass with a lambda function that has expense as its parameter.

So that leaves the expression:

your lambda function should return the value of the 'amount' key in the expense dictionary.

I hope this helps

1 Like

I’m just going to say this but until today I have never really used lambda before

I think this will help thank you

Well you are following a tutorial called " Learn Lambda Functions" so that’s not really surprising.

If you ever don’t understand something you should do a search and read one or two other sources for an explanation and examples.

w3schools and geeksforgeeks work really well for me

https://www.geeksforgeeks.org/python-lambda/

so do I need to keep the return function?

Did you look at any examples from the links I’ve sent you?

Do any of those have return in the them?

I get that but even without the return I can’t move onto the next step

Please post your updated code.

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”]}')

def total_expenses(expenses):
lambda arguments: expense

expenses =

this is my current code and it doesn’t let me move on

I fixed it I needed to change arguments to expense

1 Like

It works with:

code removed by moderator

hi @cristian.peralta

It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge. How to Help Someone with Their Code Using the Socratic Method

We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.