Skip to content

Instantly share code, notes, and snippets.

@onelharrison
Created August 15, 2021 16:14
Show Gist options
  • Save onelharrison/9269e691fa5b5d534ebe2d0431b8bfb3 to your computer and use it in GitHub Desktop.
Save onelharrison/9269e691fa5b5d534ebe2d0431b8bfb3 to your computer and use it in GitHub Desktop.
def first_name(full_name: str) -> str:
"""Extracts and returns the first name from a full name"""
return full_name.split(" ")[0]
def square(n: int) -> int:
"""Returns the square of the given number"""
return n ** 2
full_names = ["Ada Lovelace", "Katherine Johnson", "Marie Curie"]
first_names = list(map(first_name, full_names))
print(first_names) # ["Ada", "Katherine", "Marie"]
squares = list(map(square, range(1, 10)))
print(squares) # [1, 4, 9, 16, 25, 36, 49, 64, 81]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment