Don't forget to also checkout my second blog containing articles to all other related ICT topics!!

Thursday, May 3, 2012

Itertools compress method explained

The compress method: Make an iterator that filters elements from data returning only those that have a corresponding element in selectors that evaluates to True. Stops when either the data or selectors iterables has been exhausted
from itertools import compress
names = ['Robby', 'Valerie', 'Lindsey']
sex =   [1, 0, 0]
print list(compress(names, sex))


No comments:

Post a Comment