Created
April 26, 2018 15:00
-
-
Save brizandrew/7b0b87fa22b53673dcecfb3b1d70acbf to your computer and use it in GitHub Desktop.
Sort a list of dictionaries by a certain key
This file contains hidden or 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
# 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