curriculum/challenges/english/blocks/learn-lambda-functions-by-building-an-expense-tracker/6582324b5d37fe4b622bc3c0.md
Lambda functions are brief, anonymous functions in Python, ideal for simple, one-time tasks. They are defined by the lambda keyword, and they use the following syntax:
lambda x: expr
In the example above, x represents a parameter to be used in the expression expr, and it acts just like any parameter in a traditional function. expr is the expression that gets evaluated and returned when the lambda function is called.
Create a variable named test and assign it a lambda function that takes an x parameter and returns x * 2.
You should declare a variable named test.
({ test: () => assert(runPython(`_Node(_code).has_variable("test")`))})
You should assign lambda x: x * 2 to your test variable.
({ test: () => assert(runPython(`_Node(_code).find_variable("test").is_equivalent("test = lambda x: x * 2")`))})
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):
pass
--fcc-editable-region--
--fcc-editable-region--
expenses = []