Created
May 29, 2017 11:24
-
-
Save ashokbharat/aa0522a8442af0483a4ca437f435d0b8 to your computer and use it in GitHub Desktop.
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
'''Let's say I give you a list saved in a variable: a = [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]. | |
Write one line of Python that takes this list a and makes a new list that has only the even elements of this list in it.''' | |
a = [1, 4, 9, 16, 25, 36, 49, 64, 81, 100] | |
print(list(filter(lambda x:(x%2==0),a))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment