I have a dict and its keys are dates, its items are some numbers and sum of the numbers with Total as shown below. I want to group the keys by year with their sum of Total value. I know how to do it if I use fixed dict. But I will always write different changeable dates. My example list is;
{
"15-12-2017" : {
"1" : "abc",
"2" : "def",
"Total" : "2"
},
"16-12-2017" : {
"1" : "ghi",
"2" : "jkl",
"3" : "mno",
"Total" : "3"
}
"17-12-2017" : {
"1" : "ghi",
"2" : "jkl",
"3" : "mno",
"4" : "pqr",
"Total" : "4"
}
"15-12-2018" : {
"1" : "ghi",
"2" : "jkl",
"3" : "mno",
"Total" : "3"
}
"16-12-2018" : {
"1" : "ghi",
"2" : "jkl",
"Total" : "2"
}
"18-12-2019" : {
"1" : "ghi",
"2" : "jkl",
"3" : "mno",
"Total" : "3"
}
}
I want to get a new list like;
{"2017":9,"2018":5,"2019":3}
I can do only;
for key in my_list:
if key.split('-')[2] == '2017':
l_2017.append(key)
But as I said before, I will insert many changeable dates. How can I cluster them like this format?