Last active
December 27, 2019 16:39
-
-
Save edenau/148a56e624297addcbceb1805c2d4554 to your computer and use it in GitHub Desktop.
Python List Comprehension
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
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