一. map( ) 映射
l = [1,2,3,4]
print(list(map(lambda x:x+1,l))) # 获取列表中每个元素并传递给匿名函数运算保存返回值
二. zip( ) 拉链
l = [11, 22, 33, 44, 55, 66, 77]
name_list = ['jason', 'kevin', 'tony', 'jerry']
l1 = [1, 2, 3, 4, 5, 6, 7]
l2 = [8, 7, 6, 4, 3, 2, 1]
res = zip(l, name_list, l1, l2)
print(list(res))
# 结果为 [(11, 1, 8, 'jason'), (22, 2, 7, 'kevin'), (33, 3, 6, 'tony'), (44, 4, 4, 'jerry')]
# zip是按照元素个数最少的那个来决定生成多少组元素
# 元素是以列表的形式存的
三. max( )、min( ) 最大、最小值
max求最大值 min求最小值
l = [11, 22, 33, 44, 55, 66, 77]
print(max(l)) # 77
print(min(l) # 1
# 当遇到字典的时候也可以比较V值
d = {
'jason':3000,
'Bevin':1000000,
'Ascar':10000000000,
'aerry':88888
}
print(min(d,key=lambda key:d[key])) # jason
print(max(d,key=lambda key:d[key])) # Ascar
# 把K对应的V值取出来然后比较大小
四. reduce( ) 归总
from functools import reduce
d = [11, 22, 33, 44, 55, 66, 77, 88, 99]
res = reduce(lambda x, y: x + y, d)
res1 = reduce(lambda x, y: x + y, d, 100) # 还可以额外添加元素值
print(res) # 495
print(res1) # 595
五. filter( ) 过滤
l = [11, 22, 33, 44, 55]
res = filter(lambda x: x > 30, l)
print(list(res)) # [33, 44, 55]
# 可可以用列表生成器完成
l1 = [i for i in l if i > 30]