Last active
August 15, 2021 17:18
-
-
Save onelharrison/76a57f0065a16f153f23ad0a1a80d389 to your computer and use it in GitHub Desktop.
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
from typing import Any, Tuple | |
Pair = Tuple[Any, Any] | |
def pair_first(pair: Pair) -> Any: | |
"""Returns the first item in a given pair""" | |
return pair[0] | |
def pair_second(pair: Pair) -> Any: | |
"""Returns the second item in a given pair""" | |
return pair[1] | |
people = [("Marie Curie", 66), ("Katherine Johnson", 101), ("Ada Lovelace", 36)] | |
# Sort the list by name and print it | |
print(sorted(people, key=pair_first)) | |
# Sort the list by age and print it | |
print(sorted(people, key=pair_second)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment