Skip to content

Instantly share code, notes, and snippets.

@adrianmarkperea
Last active October 5, 2019 04:45
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 adrianmarkperea/3f84ba0754ff2ae1507641beae92a067 to your computer and use it in GitHub Desktop.
Save adrianmarkperea/3f84ba0754ff2ae1507641beae92a067 to your computer and use it in GitHub Desktop.
# 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