首页 > 其他 > 详细

常用函数

时间:2019-02-14 10:29:47      阅读:179      评论:0      收藏:0      [点我收藏+]

max()

height = {‘swz‘:180, ‘dj‘:170, ‘zs‘:160, ‘fll‘:150}

 

max(height, key=lambda x:height[x])

 

map():映射

namel=[‘dj‘,‘fll‘,‘zs‘]

 

map(func,namel)

map(lambda x:x+‘sb‘,namel)

 

py2正常返回

py3返回迭代器

 

reduce():合并(相加)可以处理字符串

py3需要导入

from functools import reduce

 

reduce(lambda x, y:x+y, [i for i in range(101)],200)

最后参数为初始值

 

 

filter():过滤

namel=[‘djsb‘,‘fllsb‘,‘zssb‘,‘swz‘]

 

filter(lambda x:x.endswith(‘sb‘),namel)

 

常用函数

原文:https://www.cnblogs.com/sw-z/p/10372739.html

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