6-19 day16 map filter reduce 等 4:24 ——5:00

num =[1,2,23,4,5,5,45]
rea=map(lambda x:x+1,num)
print(list(rea))//[2, 3, 24, 5, 6, 6, 46]
map (函数或者逻辑,参数(课迭代对象)) 处理原列表,顺序不变

 filter函数,需要list取值

movie_people=['alex_sb','wupeiqi_sb','linhaifeng','yuanhao_sb']
# def sb_show(n):
# return n.endswith('sb')
#--->lambda n:n.endswith('sb')

def filter_test(func,array):
ret=[]
for p in array:
if not func(p):
ret.append(p)
return ret

res=filter_test(lambda n:n.endswith('sb'),movie_people)
print(res)//['linhaifeng']
print(filter(lambda n:not n.endswith('sb'),movie_people))
res=filter(lambda n:not n.endswith('sb'),movie_people)
print(list(res))
print(list(filter(lambda n:not n.endswith('sb'),movie_people)))

<filter object at 0x009F3710>
['linhaifeng']
['linhaifeng'

filter (逻辑判断得布尔值,参数) 筛选原来的列表
true 保留




from functools import reduce

    reduce(逻辑,参数,初始值)函数  将原来列表迭代压缩在一起

# #处理序列中的每个元素,得到的结果是一个‘列表’,该‘列表’元素个数及位置与原来一样
# # map()
#
# #filter遍历序列中的每个元素,判断每个元素得到布尔值,如果是True则留下来
#

abs()绝对值

猜你喜欢

转载自www.cnblogs.com/yikedashuyikexiaocao/p/9196935.html