Created
August 18, 2020 15:26
-
-
Save ycui1/0baf5f7e3c41186af5049773234fefb9 to your computer and use it in GitHub Desktop.
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
>>> # 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