Created
October 7, 2021 16:00
-
-
Save OriHoch/893b194cfe16535cadf65969a76864fd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import defaultdict | |
def sum_per_date(rows): | |
date_sums = defaultdict(int) | |
for row in rows: | |
date_sums[row['date']] += row['amount'] | |
return dict(date_sums) | |
sum_per_date([ | |
{'date': '2021-10-01', 'amount': 50}, | |
{'date': '2021-10-01', 'amount': 60}, | |
{'date': '2021-10-02', 'amount': 20} | |
]) | |
# { | |
# '2021-10-01': 110, | |
# '2021-10-02': 20 | |
# } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment