Skip to content

Instantly share code, notes, and snippets.

@Kush1101
Created September 26, 2020 16:03
Show Gist options
  • Save Kush1101/837f3eef065a08dc068994dbaf4b53dd to your computer and use it in GitHub Desktop.
Save Kush1101/837f3eef065a08dc068994dbaf4b53dd to your computer and use it in GitHub Desktop.
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