I have a dictionary of times and counts. I need to sort the dict so that it is in ascending order by time. I need help getting the sort to do something useful. Right now I am dropping the AM/PM to remove complexity but I am aware that I'm running into a problem there since I'm losing information.
Calling
sorted(myDict, key = bytime_key)
with
def bytime_key(input):
shorter_input = re.match(r'^(.*) \w\w$', input).group(1)
time = datetime.strptime(shorter_input, '%m/%d/%Y %H:%M:%S')
return(time)
is fine, save that it doesn't actually change the order, so I'm missing something fundamental here.
Sample dictionary
myDict = {'1/15/2016 10:41:00 AM': 11, '1/15/2016 10:43:00 AM': 4,
'1/15/2016 10:22:00 AM': 46, '1/15/2016 10:30:00 AM': 15,
'1/15/2016 10:59:00 AM': 34, '1/15/2016 12:06:00 PM': 12,
'1/15/2016 11:42:00 AM': 11, '1/15/2016 12:22:00 PM': 1,
'1/15/2016 12:18:00 PM': 5, '1/15/2016 10:52:00 AM': 6}