>>>a=[1,2,3,4,5,6,7]
>>>b=filter(lambda x:x>5, a)
>>>print b
[6,7]
如果filter参数值为None,就使用identity()函数,list参数中所有为假的元素都将被删除。如下所示:
>>>a=[0,1,2,3,4,5,6,7]
>>>b=filter(None, a)
>>>print b
[1,2,3,4,5,6,7]
map函数func作用于给定序列的每个元素,并用一个列表来提供返回值。
>>>a=[0,1,2,3,4,5,6,7]
>>>map(lambda x:x+3, a
[3,4,5,6,7,8,9,10]
>>>a=[1,2,3]
>>>b=[4,5,6]
>>>map(lambda x,y:x+y, a,b)
[5,7,9]
>>>a = [1,2,3,4,5]
>>>reduce(lambda x,y:x+y,a)
15