Skip to content

Instantly share code, notes, and snippets.

@toast38coza
Created October 18, 2011 05:35
Show Gist options
  • Save toast38coza/1294689 to your computer and use it in GitHub Desktop.
Save toast38coza/1294689 to your computer and use it in GitHub Desktop.
Sort a list of dicts by a key value in the dict
# 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