您好,登錄后才能下訂單哦!
?? filter()函數
?????????? filter()函數是個過濾器,它的作用就是在海量的數據里提取出有用的信息
>>> help(filter)
Help on class filter in module builtins:class filter(object)
? |? filter(function or None, iterable) --> filter object
? |?
? |? Return an iterator yielding those items of iterable for which function(item)
? |? is true. If function is None, return the items that are true.
? |?
? |? Methods defined here:
? |?
? |? __getattribute__(self, name, /)
? |????? Return getattr(self, name).
? |?
? |? __iter__(self, /)
|????? Implement iter(self).
? |?
? |? __next__(self, /)
? |????? Implement next(self).
? |?
? |? __reduce__(...)
? |????? Return state information for pickling.
? |?
? |? ----------------------------------------------------------------------
? |? Static methods defined here:
? |?
? |? __new__(*args, **kwargs) from builtins.type
? |????? Create and return a new object.? See help(type) for accurate signature.?????? filter()函數有兩個參數,第一個參數是一個函數也可以是None,第二個參數是可迭代對象iterable,如果第一個參數是
函數,則將第二個參數可迭代對象的每個元素作為函數的參數進行計算,把返回為True的值篩選出來;如果第一個參數是
None,則直接將第二個參數中為True的值篩選出來。
?????? 例:
>>> list1=filter(None,[1,0,2,True,False])
>>> list(list1)
[1, 2, True]
>>> list(filter(lambda x:x%2,range(10)))
[1, 3, 5, 7, 9]
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。