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)))



posted @ 2018-04-01 11:43  阜阳小全  阅读(140)  评论(0编辑  收藏  举报