Created
October 18, 2011 05:35
-
-
Save toast38coza/1294689 to your computer and use it in GitHub Desktop.
Sort a list of dicts by a key value in the dict
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# given a list such as: | |
# list = [{'title':title, 'date': x.created_on}, ...] | |
# you can sort on a dict key like such | |
list.sort(key=lambda item:item['date'], reverse=True) | |
#source: http://stackoverflow.com/questions/652291/sorting-a-list-of-dictionary-values-by-date-in-python |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment