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))
['Robby']
No comments:
Post a Comment