map函数

#将每个数字自增1,自减1,直接每个数字平方
num_1= [1,12,3,4,5,11]
def add1(x):
return x + 1
def reduce1(x):
return x - 1
def pf(x):
return x **2
def map1(func,ss):
d = []
for i in ss:
d.append(func(i))
return d
print(map1(add1,num_1))
print(map1(reduce1,num_1))
print(map1(pf,num_1))

# 终极版:
num_1= [1,12,3,4,5,11]
def map1(func,ss):
d = []
for i in ss:
d.append(func(i))
return d
print(map1(lambda x:x+1,num_1))
print(map1(lambda x:x-1,num_1))
print(map1(lambda x:x**2,num_1))



msg = 'liuhaiquan'
print(list(map(lambda x:x.upper(),msg)))



原文地址:https://www.cnblogs.com/lhqlhq/p/8686099.html