I have this dictionary that has an arbitrary number of keys which are dates, I'm trying to sum up the income of each key, my problem is I don't the number of keys at any given point.
dictionary
sum up
Here is the dictionary
Tax_table = { "2021-01-16": { "Income": 400.19, ...other key, values... }, "2021-01-18": { "Income": 578 ...other key, values... }, "2021-01-21": { "Income": 1877, ....other key, values... } }
Is there a way to sum up all incomes of the table?
If you want to sum up all incomes of the table, the below code will work:
total_sum = 0 for i in Tax_table: total_sum = total_sum + Tax_table[i]['Income'] print(total_sum)
1.4m articles
1.4m replys
5 comments
57.0k users