首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > perl python >

python 惯用函数 filter

2013-08-01 
python 常用函数 filter返回sequence中,能使function返回True的值,如果function?为None,则sequence全部返

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]

热点排行