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