为了账号安全,请及时绑定邮箱和手机立即绑定
课程 \ python进阶

python进阶

2-7 python中自定义排序函数
def cmp_ignore_case(s1, s2):
u1=s1.upper()
u2=s2.upper()
if u1<u2:
return -1
if u1>u2:
return 1
return 0

print sorted(['bob', 'about', 'Zoo', 'Credit'], cmp_ignore_case)
2018-03-28 查看完整代码
2-6 python中filter()函数
import math

def is_sqr(x):
return math.sqrt(x).is_integer()

print filter(is_sqr, range(1, 101))
2018-03-28 查看完整代码
2-5 python中reduce()函数
def prod(x, y):
return x*y

print reduce(prod, [2, 4, 5, 7, 12])
2018-03-28 查看完整代码
2-4 python中map()函数
def format_name(s):
return s[0].upper()+s[1:].lower()

print map(format_name, ['adam', 'LISA', 'barT'])
2018-03-28 查看完整代码
2-3 python把函数作为参数
import math

def add(x, y, f):
return f(x) + f(y)

print add(25, 9,math.sqrt)
2018-03-28 查看完整代码
意见反馈 帮助中心 APP下载
官方微信