Skip to content

Instantly share code, notes, and snippets.

@pinkpretty
Created September 21, 2016 06:25
Show Gist options
  • Save pinkpretty/48c8e0a700017c54d3352ca12d4117f5 to your computer and use it in GitHub Desktop.
Save pinkpretty/48c8e0a700017c54d3352ca12d4117f5 to your computer and use it in GitHub Desktop.
'''
this is practicepython exercise - 7
'''
'''
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.
'''
import random
list =[random.randrange(1,101) for i in range(10)]
print(list)
even = [item for item in list if(item%2 == 0)]
print(even)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment