446

2 分钟

#filter

说明:过滤数据。

def filter(fn, iterable): ''' 过滤数据 :param fn: 回调函数,返回 True 是元素保留,返回 False 时元素去除 :param iterable: 要过滤的可迭代对象 :return: 过滤后的可迭代对象 '''

示例:

numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9] print(filter(lambda x : x%2 == 0, numbers)) print(list(filter(lambda x : x%2 == 0, numbers)))

>>> Establishing WebAssembly Runtime.

>>> Standby.

Powered by Shift.

创建于 2025/5/9

更新于 2025/5/11