Ethan1
1
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 
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
Ethan1
3
I’m just going to say this but until today I have never really used lambda before
Ethan1
4
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/
Ethan1
6
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?
Ethan1
8
I get that but even without the return I can’t move onto the next step
Please post your updated code.
Ethan1
10
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 =
Ethan1
11
this is my current code and it doesn’t let me move on
Ethan1
12
I fixed it I needed to change arguments to expense
1 Like