Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# The basic syntax is as follows:
# new_list = [<expression> <for loop(s)> <conditions>]
my_list = [1, 2, 3, 4, 5]
doubled = [x*2 for x in my_list] # no conditions in this case
print(doubled) # => [2, 4, 6, 8, 10]
# Equivalent to the following for loop:
doubled = []
for x in my_list:
doubled.append(x*2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment