每天CookBook之Python-017

  • compress的使用
from itertools import compress

address = [
    '5412 N CLARK',
    '5148 N CLARK',
    '5800 E 58TH',
    '2122 N CLARK'
    '5645 N RAVENSWOOD',
    '1060 W ADDISON',
    '4801 N BROADWAY',
    '1039 W GRANVILLE',
]
counts = [0, 3, 10, 4, 1, 7, 6, 1]

more5 = [n > 5 for n in counts]
print(more5)
print(address)
print(list(compress(address, more5)))
[False, False, True, False, False, True, True, False]
['5412 N CLARK', '5148 N CLARK', '5800 E 58TH', '2122 N CLARK5645 N RAVENSWOOD',
 '1060 W ADDISON', '4801 N BROADWAY', '1039 W GRANVILLE']
['5800 E 58TH', '4801 N BROADWAY', '1039 W GRANVILLE']
posted @ 2016-07-09 10:02  4Thing  阅读(99)  评论(0编辑  收藏  举报