Created
September 6, 2017 18:21
-
-
Save srahuliitb/8cde456ae79f53c75d0494c2b28d2a53 to your computer and use it in GitHub Desktop.
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.
This file contains hidden or 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
| a = [x ** 2 for x in range(1, 11)] | |
| a_even = [] | |
| for i in a: | |
| if i % 2 == 0: | |
| a_even.append(i) | |
| print a_even |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment