I am grouping a list of objects together by their timestamp:
object_list = [
{
timestamp: datetime.strptime("01/01/2014", "%d/%m/%y"),
},
{
timestamp: datetime.strptime("12/05/2014", "%d/%m/%y"),
},
{
timestamp: datetime.strptime("03/01/2014", "%d/%m/%y"),
},
{
timestamp: datetime.strptime("01/01/2014", "%d/%m/%y"),
}]
date_grouped_objects = defaultdict(list)
for obj in object_list:
date_grouped_objects[obj.timestamp].append(obj)
Which gives me exactly what I want, a list of objects grouped together by their timestamp attribute.
Question: I now want to sort date_grouped_objects by the keys (the timestamps), but it isn't clear how you can use sorted to achieve this? So the most group with the most recent date would be last
So what I'm after is:
[
["01/01/2014"] = [...],
["03/01/2014"] = [...],
["12/05/2014"] = [...],
]
Where the keys are actually date objects, not strings.