Sorting dictionary by datetime value

pete suchsland visiondoctor2020 at gmail.com
Tue Feb 11 03:31:42 CET 2014


How about make it simple by using sorted(a.values()) ...

>>> a = {}
>>> a['first'] = datetime.datetime.now()
>>> a['second'] = datetime.datetime.now()
>>> a['third'] = datetime.datetime.now()
>>> a['forth'] = datetime.datetime.now()
>>> a['fifth'] = datetime.datetime.now()

>>> sorted(a.values())
[datetime.datetime(2014, 2, 10, 19, 24, 35, 163585), datetime.datetime(2014, 2, 10, 19, 24, 53, 244532), datetime.datetime(2014, 2, 10, 19, 25, 9, 483683), datetime.datetime(2014, 2, 10, 19, 25, 25, 581743), datetime.datetime(2014, 2, 10, 19, 25, 37, 789907)]



More information about the Python-list mailing list