Skip to content

Instantly share code, notes, and snippets.

@ehedaoo
Created May 11, 2017 05:01
Show Gist options
  • Save ehedaoo/f819b18e45b2e7bd2aef81f150f07603 to your computer and use it in GitHub Desktop.
Save ehedaoo/f819b18e45b2e7bd2aef81f150f07603 to your computer and use it in GitHub Desktop.
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 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]
b = list(filter(lambda x: x % 2 == 0, a))
print(b)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment