Hey folks, I’m trying to wrap my head around how these lambda functions are being used and the expense/argument.
In the following code associated with the exercise I get being able to use expense as its being created in the for loop, but I’m unsure of how we are using expense in the other functions if expense is a local variable for the print_expenses() function. I’m obviously missing something in my understanding. Thanks in advance for any help!
I just don’t get what the lambda function or the regular function do by them selves. I get we are wanting to pull the values from the ‘amount’ key in the dictionary, just not exactly how it’s working.
map function uses the function that’s passed in, let’s call it callback function. When iterating over elements of the expenses, each element is passed to the callback function.
I’m not sure if that’s going to answer your question.
I appreciate you trying to help me wrap my cave man brain around this. I added the function below to the program and get the error below when I try to get that return value after passing the expenses dictionary which contains 1 expense, so 1 amount and 1 category.
File “/Users/me/Desktop/freeCodeCamp/Expense_Tracker.py”, line 15, in get_expense_amount
return expense[‘amount’]
~~~~~~~^^^^^^^^^^
TypeError: list indices must be integers or slices, not str
This works if paired with the map function and the entire expenses dictionary as with the total_expenses function, but I would think it would return some value if that value is iterating over the entire expenses dictionary.