筛选序列中的大于0元素
In [1]: from itertools import compress
In [2]: a = ['s', 'v', 'x']
In [3]: b = [1, 0, 7]
In [4]: more0 = [n > 0 for n in b]
In [5]: more0
Out[5]: [True, False, True]
In [6]: list(compress(a,b))
Out[6]: ['s', 'x']
筛选序列中的大于0元素
In [1]: from itertools import compress
In [2]: a = ['s', 'v', 'x']
In [3]: b = [1, 0, 7]
In [4]: more0 = [n > 0 for n in b]
In [5]: more0
Out[5]: [True, False, True]
In [6]: list(compress(a,b))
Out[6]: ['s', 'x']