Skip to content

Instantly share code, notes, and snippets.

@adrianmarkperea
Created October 5, 2019 04:47
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/95738396ae55857959ef16dae9c35e8a to your computer and use it in GitHub Desktop.
Save adrianmarkperea/95738396ae55857959ef16dae9c35e8a to your computer and use it in GitHub Desktop.
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