Skip to content

Instantly share code, notes, and snippets.

@brizandrew
Created April 26, 2018 15:00
Show Gist options
  • Save brizandrew/7b0b87fa22b53673dcecfb3b1d70acbf to your computer and use it in GitHub Desktop.
Save brizandrew/7b0b87fa22b53673dcecfb3b1d70acbf to your computer and use it in GitHub Desktop.
Sort a list of dictionaries by a certain key
# Source: https://wiki.python.org/moin/SortingListsOfDictionaries
def sortDictList(arr, sort_key):
output = [(dict_[sort_key], dict_) for dict_ in arr]
output.sort()
return [dict_ for (key, dict_) in output]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment