def cmp_ignore_case(s1, s2):
if s1.upper()>s2.upper():
return 1
else :
return -1
print sorted(['bob', 'about', 'Zoo', 'Credit'], cmp_ignore_case)
if s1.upper()>s2.upper():
return 1
else :
return -1
print sorted(['bob', 'about', 'Zoo', 'Credit'], cmp_ignore_case)
2015-09-09
# -*- coding: utf-8 -*
#中文py注释支持 必须在所有注释之前添加
#网上找到的Python函数参数介绍
#http://demo.netfoucs.com/pipisorry/article/details/39123103
#args kw是习惯写法 如同C中的argc argv
#中文py注释支持 必须在所有注释之前添加
#网上找到的Python函数参数介绍
#http://demo.netfoucs.com/pipisorry/article/details/39123103
#args kw是习惯写法 如同C中的argc argv
2015-09-08
def format_name(s):
return s.capitalize()
print map(format_name, ['adam', 'LISA', 'barT'])
return s.capitalize()
print map(format_name, ['adam', 'LISA', 'barT'])
2015-09-07
import time
def performance(f):
def fn(*args,**kw):
t1=time.time()
t2=time.time()
print 'call '+f.__name__+'() in %fs' %(t2-t1)
return f(*args,**kw)
return fn
@performance
def factorial(n):
return reduce(lambda x,y: x*y, range(1, n+1))
print factorial(10)
def performance(f):
def fn(*args,**kw):
t1=time.time()
t2=time.time()
print 'call '+f.__name__+'() in %fs' %(t2-t1)
return f(*args,**kw)
return fn
@performance
def factorial(n):
return reduce(lambda x,y: x*y, range(1, n+1))
print factorial(10)
2015-09-07