Created
September 26, 2020 16:03
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
from itertools import compress | |
data = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20] | |
selector = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1] | |
for i in compress(data, selector): | |
print(i, end=" ") | |
# OUTPUT | |
# Simply prints all numbers for which the corresponding boolean value in selector | |
#is True, in this case all the even numbers upto 10. | |
""" | |
0 2 4 6 8 10 | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment