Python 内建函数 - filter(function, iterable)

本文介绍了Python内置函数filter的功能,它用于根据指定条件筛选序列元素,并返回一个迭代器。当function为空时,filter相当于去除false值的元素。文中包含filter函数的直译解释和使用示例。
摘要由CSDN通过智能技术生成

Manual

Construct an iterator from those elements of iterable for which function returns true. iterable may be either a sequence, a container which supports iteration, or an iterator. If function is None, the identity function is assumed, that is, all elements of iterable that are false are removed.

Note that filter(function, iterable) is equivalent to the generator expression (item for item in iterable if function(item)) if function is not None and (item for item in iterable if item) if function is None.

See itertools.filterfalse() for the complementary function that returns elements of iterable for which function returns false.

直译

function 可以返回真值的 iterable 的元素构造一个迭代器。iterable可以是序列、支持迭代的容器或是一个迭代器。如果function为空,则假定恒等函数,即移除所有为false值的迭代元素。
注意:如果

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值