Sorting a list of dictionaries by dictionary key

Nico Grubert nicogrubert at gmail.com
Wed May 3 09:44:22 EDT 2006


> assuming that DateTime returns something that compares correctly, you can
> do something like:
> 
>     def sortkey(item):
>         return item.get("from_datetime")
> 
>     data.sort(key=sortkey)
> 
> (assuming Python 2.4 or later)

Thank you very much, Frederik. Unfortunately, I can only use Python 2.3.5.



More information about the Python-list mailing list