I'm trying to sort a DICT by Keys, but the big issue i founded first the KEYS values is a 'STRING' based on quarterly period.
Follow a example:
ex_dict = {
"6/2021": 1,
"9/2020": 1,
"6/2019": 1,
"3/2020": 1,
"6/2020": 1,
"9/2019": 1,
"3/2021": 1,
"3/2019": 1,
}
I know i can used the function sorted(), to order the keys then use list comprehension to order with original values.
Something like this:
in: print({k: v for k, v in sorted(ex_dict.items())})
out: {
'3/2019': 1,
'3/2020': 1,
'3/2021': 1,
'6/2019': 1,
'6/2020': 1,
'6/2021': 1,
'9/2019': 1,
'9/2020': 1
}
But he only orders using the first number, how i can transform this keys to DATETIME to make order on the right way.