Skip to content

Instantly share code, notes, and snippets.

@ycui1
Created August 18, 2020 15:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ycui1/0baf5f7e3c41186af5049773234fefb9 to your computer and use it in GitHub Desktop.
Save ycui1/0baf5f7e3c41186af5049773234fefb9 to your computer and use it in GitHub Desktop.
>>> # A list of dictionary objects for sorting
>>> grades = [{'name': 'John', 'score': 97},
... {'name': 'David', 'score': 96},
... {'name': 'Jennifer', 'score': 98},
... {'name': 'Ashley', 'score': 94}]
>>> def sorting_grade(x):
... return x['score']
...
>>> sorted(grades, key=sorting_grade)
[{'name': 'Ashley', 'score': 94}, {'name': 'David', 'score': 96}, {'name': 'John', 'score': 97}, {'name': 'Jennifer', 'score': 98}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment