Created
May 2, 2023 08:51
-
-
Save tinshade/48097e0fe151ebd5ebdfffc43bfe6d62 to your computer and use it in GitHub Desktop.
Sorting a list of dicts based on values from within 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
list_to_be_sorted = [{'salary': 1000, 'n':'a'},{'salary': 1000, 'n':'b'},{'salary': 100, 'n':'b'}] | |
newlist = sorted( list_to_be_sorted, key=lambda k: (k['salary'], k['n']) ) | |
print(newlist) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment