Describing itertools.compress(iterable, flags)
- The 
compressfunction is used to cycle through each element of an iterable, while filtering only certain values - The selected elements within the iterator are based on the 
flagsparameter compressreturns an iterator of selectediterableelements- The iterable comes from the 
iterableparameter - The selected elements come from the 
flagsparameter 
Illustrating the compress Function
>>> from itertools import compress
>>> letters = 'abcde'
>>> flags = [1,0,0,1,0]
>>> itr = compress(letters, flags)
>>> for i in itr: print(i)
a
dReferences
Previous
Next