Last active
October 5, 2019 04:45
-
-
Save adrianmarkperea/3f84ba0754ff2ae1507641beae92a067 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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