I have a Python dictionary like this:
{
'apple': datetime.datetime(2012, 12, 20, 0, 0, tzinfo=<UTC>),
'orange': datetime.datetime(2012, 2, 4, 0, 0, tzinfo=<UTC>),
'raspberry': datetime.datetime(2013, 1, 9, 0, 0, tzinfo=<UTC>)
}
Solution:
sorted(dct.items(), key=lambda p: p[1], reverse=True)
Output:
=> [('raspberry', datetime.datetime(2013, 1, 9, 0, 0)),
('apple', datetime.datetime(2012, 12, 20, 0, 0)),
('orange', datetime.datetime(2012, 2, 4, 0, 0))]