Learn Lambda Functions by Building an Expense Tracker - Step 16

Hello I don’t understand what I have to do. Also I don’t understand what the paramter in the lambda function is. In general I have no clue what I have to do in this step. SIDENOTE: I think you should add a solution tab so if you don’t understand you can check the answer.

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: x * 
        return expense["Amount"]

# User Editable Region


expenses = []

Challenge Information:

Learn Lambda Functions by Building an Expense Tracker - Step 16

Hi @badcharm

Here is an article about lambda functions you may find helpful.

In general these anonymous functions do not use the return keyword.

Happy coding

A direct solution doesn’t actually help anyone though. It would be ridiculously easy for you to just go there instead of try to solve the problem. For some, I don’t think they’d every look back and try to solve it themselves. As that is a giant easily avoidable risk, it really shouldn’t be implemented. Though maybe I could try suggesting some kind of secondary hint system for the lessons that doesn’t require code feedback .

Back in step 11, Python lamdas were introduced.

In this challenge, our goal is to create an lamda with a parameter of expense. And then the lamda function returns the value of the amount key in the expense parameter. The expense parameter just so happens to be a dictionary.

I hope this help. :slight_smile:

I came here looking for help on this too. The article @Teller linked to cracked it for me. It was this line particularly:

Notice that the anonymous function does not have a return keyword. This is because the anonymous function will automatically return the result of the expression in the function once it is executed

So we don’t need the lamda function to do anything but call what we’ve been told to return

1 Like