Back to Freecodecamp

Step 12

curriculum/challenges/english/blocks/learn-lambda-functions-by-building-an-expense-tracker/65822308ded1ba4632f66aa3.md

latest1.3 KB
Original Source

--description--

A dictionary is another built-in data type in Python. A dictionary is a collection of data in the form of key-value pairs. Dictionaries are defined with curly braces ({}) and they contain key-value pairs separated by commas. Each key is followed by a colon (:) and the value:

py
{'amount': 50.0, 'category': 'Food'}

In the example above, 'amount' and 'category' are keys, and 50.0 and 'Food' are their corresponding values.

Create a dictionary with a key 'amount' and value of the amount parameter and pass your new dictionary to the .append() call.

--hints--

You should pass a dictionary as the argument to the .append() method.

js
({ test: () => assert(runPython(`
import ast
node = _Node(_code).find_function("add_expense").find_calls("append")[0].find_call_args()
len(node) == 1 and isinstance(node[0].tree, ast.Dict)
`)) })

You should pass {'amount': amount} as the argument to the .append() method.

js
({ test: () => assert(runPython(`_Node(_code).find_function("add_expense").has_stmt("expenses.append({'amount': amount})")`)) })

--seed--

--seed-contents--

py
--fcc-editable-region--
def add_expense(expenses, amount, category):
    expenses.append()
--fcc-editable-region--

expenses = []