Skip to content

Instantly share code, notes, and snippets.

View stevenrouk's full-sized avatar

Steven Rouk stevenrouk

View GitHub Profile
@stevenrouk
stevenrouk / list_comprehension_example.py
Created August 25, 2019 21:48
A short, easy example of list comprehensions in Python.
# List comprehension to create a list the numbers 1 to 20 squared.
list_of_squares = [x**2 for x in range(1, 20)]
# The above list comprehension is the same as this for-loop:
list_of_squares = []
for x in range(1, 20):
list_of_squares.append(x**2)