filter(function, iterable)
参数
function -- 判断函数。
iterable -- 可迭代对象。
#过滤列表中所有奇数
def is_odd(n):
return n % 2 == 1
tmplist = filter(is_odd, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
newlist = list(tmplist)
print(newlist)
filter()函数使用
最新推荐文章于 2025-04-11 01:30:00 发布