Skip to content

Instantly share code, notes, and snippets.

@onelharrison
Last active August 15, 2021 17:18
Show Gist options
  • Save onelharrison/76a57f0065a16f153f23ad0a1a80d389 to your computer and use it in GitHub Desktop.
Save onelharrison/76a57f0065a16f153f23ad0a1a80d389 to your computer and use it in GitHub Desktop.
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