Created
September 6, 2013 06:59
-
-
Save gideondsouza/6460422 to your computer and use it in GitHub Desktop.
Python Comprehensions 2
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
>>> L4 = [x*x for x in range(10)] #this will evaluate to a list of squares from 1 to 10 | |
>>> L4 | |
[0, 1, 4, 9, 16, 25, 36, 49, 64, 81] | |
>>> #the next comprehension will evaluate to a list of even numbers from 1 to 20 | |
>>> L3 = [x for x in range(20) if x % 2 == 0] | |
>>> L3 | |
[0, 2, 4, 6, 8, 10, 12, 14, 16, 18] | |
>>> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment