Skip to content

Instantly share code, notes, and snippets.

@srahuliitb
Created September 6, 2017 18:21
Show Gist options
  • Select an option

  • Save srahuliitb/8cde456ae79f53c75d0494c2b28d2a53 to your computer and use it in GitHub Desktop.

Select an option

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.
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