str = ["a","b","c","d"]
def ff(s):
if s != "c":
return s
dd = filter(ff,str) #dd迭代器 filter只过滤不改变
print(list(dd))
print(dd)
print("---------------------------------------------------------- ")
str2=["g","h","k","l"]
def ff2(gg):
return gg+"gg"
ffd = filter(ff2,str2) #filter只过滤不改变
print(list(ffd)) #['g', 'h', 'k', 'l']
print("---------------------------------------------------------- ")
mapstr =["a","b","c"]
def mapfun(mapf):
return mapf+"m"
ccmap = map(mapfun,mapstr)
print(ccmap)
print(list(ccmap))
print("---------------------------------------------------------- ")
from functools import reduce
red = [1,2,3,4,5]
def redu(x,y): #必须是两个参数
return x * y
rr = reduce(redu,red) #range(1,101)
print(rr)
print("---------------------------------------------------------- ")
#匿名函数
la = reduce(lambda fa,fb : fa * fb,range(1,6))
print(la)