Sorting a list of dictionaries by dictionary key
Nico Grubert
nicogrubert at gmail.com
Wed May 3 08:46:23 EDT 2006
Hi there,
I am looking for a way to sort a list containing dictionaries.
This is my example list:
[{'Title': 'ABC', 'from_datetime': DateTime('2006/04/25 12:45:00
GMT+2')}, {'Title': 'DEF', 'from_datetime': DateTime('2006/04/18
12:45:00 GMT+2')}, {'Title': 'GHI', 'from_datetime':
DateTime('2006/03/10 12:45:00 GMT+2')}]
I want to sort the list by dictionary's key 'from_datetime' so the
sorted list should be:
[{'Title': 'GHI', 'from_datetime': DateTime('2006/03/10 12:45:00
GMT+2')}, {'Title': 'DEF', 'from_datetime': DateTime('2006/04/18
12:45:00 GMT+2')}, {'Title': 'ABC', 'from_datetime':
DateTime('2006/04/25 12:45:00 GMT+2')}]
Any idea how I can sort this list?
Thank you very much in advance,
Nico
More information about the Python-list
mailing list