python 常用函数 filter
返回sequence中,能使function返回True的值,如果function?为None,则sequence全部返回
filter(...)
??? filter(function or None, sequence) -> list, tuple, or string
???
??? Return those items of sequence for which function(item) is true.? If
??? function is None, return the items that are true.? If sequence is a tuple
??? or string, return the same type, else return a list.
>>>
>>>
>>> a= [1,2,3,4]
>>>
>>> filter(None, a)
[1, 2, 3, 4]
>>> filter(lambda p:p%2, a)
[1, 3]