Skip to content

Instantly share code, notes, and snippets.

@ycui1
Created May 22, 2020 13:24
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save ycui1/f2f8457c30253e2bee5d2428017b4121 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