Created
October 5, 2019 04:47
-
-
Save adrianmarkperea/95738396ae55857959ef16dae9c35e8a 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
my_list = [1, 2, 5, 6, 9, 21, 30] | |
odds = [x for x in my_list if x % 2 == 1] | |
print(odds) # => [1, 5, 9, 21] | |
# Equivalent to the following for loop: | |
odds = [] | |
for x in my_list: | |
if x % 2 == 1: | |
odds.append(x) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment