赞
踩
python的这个内置函数我之前竟然没用过hhh
看下文档就懂了:
Init signature: filter(self, /, *args, **kwargs)
Docstring:
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.
Type: type
返回一个迭代器,
如果第一个参数为function
,而不为None
,则新迭代器为:
def new_iter():
for item in 旧迭代器:
if function(item):
yield item
如果function为None,则返回为true的项目:
def new_iter():
for item in 旧迭代器:
if bool(item):
yield item
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。