Skip to content

Instantly share code, notes, and snippets.

@gideondsouza
Created September 6, 2013 06:59
Show Gist options
  • Save gideondsouza/6460422 to your computer and use it in GitHub Desktop.
Save gideondsouza/6460422 to your computer and use it in GitHub Desktop.
Python Comprehensions 2
>>> 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