Skip to content

Instantly share code, notes, and snippets.

@edenau
Last active December 27, 2019 16:39
Show Gist options
  • Save edenau/148a56e624297addcbceb1805c2d4554 to your computer and use it in GitHub Desktop.
Save edenau/148a56e624297addcbceb1805c2d4554 to your computer and use it in GitHub Desktop.
Python List Comprehension
print(list(map(add_func, aList)))
print([x ** 2 for x in aList])
# [0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
# [0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
print(list(filter(is_odd, aList)))
print([x for x in aList if x%2 == 1])
# [1, 3, 5, 7, 9]
# [1, 3, 5, 7, 9]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment