Skip to content

Instantly share code, notes, and snippets.

@tinshade
Created May 2, 2023 08:51
Show Gist options
  • Save tinshade/48097e0fe151ebd5ebdfffc43bfe6d62 to your computer and use it in GitHub Desktop.
Save tinshade/48097e0fe151ebd5ebdfffc43bfe6d62 to your computer and use it in GitHub Desktop.
Sorting a list of dicts based on values from within the dict.
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