Symptom
build_category_filters() creates a dict of filter functions, one per category. But every filter matches the last category in the list, regardless of which key you use.
filters = build_category_filters(["food", "transport", "entertainment"])
food_expense = Expense(10, "food", "Lunch", date(2024, 1, 1))
print(filters["food"](food_expense)) # False -- should be True!
print(filters["entertainment"](food_expense)) # True -- wrong!
What you know
The function loops over a list of category names and creates a lambda for each one. The lambdas are stored in a dictionary keyed by category name. But when you actually call any of them, they all behave as if the category is the last item from the list.
Hints
Python
Python ready
Test Output
▶
Click "Run Tests" to execute your code