Python/ref func filter
来自菜鸟教程
<languages />
Python filter()函数
例
过滤该数组,并返回一个仅包含等于或大于18的值的新数组:
ages = [5, 12, 17, 18, 24, 32]
def myFunc(x):
if x < 18:
return False
else:
return True
adults
= filter(myFunc, ages)
for x in adults:
print(x)
定义和用法
The
filter()
函数通过项目过滤项目以测试项目是否被接受时,返回一个迭代器。
句法
filter(function, iterable)
参数值
| 参数 | 描述 |
|---|---|
| function | 为可迭代项中的每个项目运行的功能 |
| iterable | 可迭代的被过滤 |