首页 > 其他 > 详细

map函数

时间:2018-04-01 12:32:57      阅读:205      评论:0      收藏:0      [点我收藏+]
#将每个数字自增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)))



map函数

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!