Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DugalMcCrow/26dbc538eb5165a79c2a925447ff1aec to your computer and use it in GitHub Desktop.
Save DugalMcCrow/26dbc538eb5165a79c2a925447ff1aec to your computer and use it in GitHub Desktop.
>>> # Create a list for subsequent operations
>>> numbers = [1, 2, 3, 4, 5, 6]
>>>
>>> # Typical way to create a list consisting of squares
>>> squares0 = []
>>> for number in numbers:
... squares0.append(number*number)
...
>>> # List comprehensions
>>> squares1 = [number*number for number in numbers]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment