Iteration Classes
itertools.compress()
Keep values whose corresponding selector is truthy. Stop when either input is exhausted.
Formal Syntax & Structure
python syntaxpython
itertools.compress(data, selectors)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| data | iterable | Values to select from. |
| selectors | iterable | Truth-tested selectors corresponding to data. |
Return Value
iterator
The iterator result described above.
Working Example
Example Snippetpython
import itertoolsprint(list(itertools.compress("ABCD",[1,0,1,0])))