>>> ss=[1,2,3,4,5,6]
>>> map(lambda x: x if not x%2 else '',ss)
<map object at 0x01B75FB0>
>>> [var for var in map(lambda x: x if not x%2 else '',ss)]
['', 2, '', 4, '', 6]
>>> filter(lambda x: x,map(lambda x: x if not x%2 else '',ss))
<filter object at 0x01B75FB0>
>>> [var for var in filter(lambda x: x,map(lambda x: x if not x%2 else '',ss))]
[2, 4, 6]
python中的map和filter操作
最新推荐文章于 2024-01-31 18:03:29 发布