当前位置: 首页 > 工具软件 > compress > 使用案例 >

compress

薛文斌
2023-12-01

筛选序列中的大于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']

 

 类似资料: