filter
filter(func, list)
func
: 对list每个item进行条件过滤的定义list
: 需要过滤的列表res = filter(lambda x:x > 1, [0,1,2])
<filter at 0x4f3af70> -> [1,2]
map
是否满足条件
返回对应的True与Falsemap(func, list)
func
: 对List每个item进行条件满足的判断list
: 需要过滤的列表res = map(lambda x:x > 1, [0,1,2])
<map at 0x4f3af70> -> [False, False, True]
reduce
reduce(func, list)
func
: 对 数据累加的函数list
: 需要处理的列表res = reduce(lambda x,y: x + y, [0,1,2])
->
3from functools import reduce
# coding:utf-8
from functools import reduce
frunts = ['apple', 'banana', 'orange']
result = filter(lambda x: 'e' in x, frunts)
print(list(result))
print(frunts)
def filter_func(item):
if 'e' in item:
return True
print('--------')
filter_result = filter(filter_func, frunts)
print(list(filter_result))
map_result = map(filter_func, frunts) # > all
print(list(map_result))
reduce_result = reduce(lambda x, y: x + y, [2, 1, 2, 100])
print(reduce_result)
reduce_result_str = reduce(lambda x, y: x + y, frunts)
print(reduce_result_str)
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有