input = ['adam','LISA','barT']
def f(x):
return x.capitalize()
print map(f,input)
def f(x):
return x.capitalize()
print map(f,input)
2017-07-29
def cmp_ignore_case(s1, s2):
a = s1.capitalize()
b = s2.capitalize()
if a < b:
return -1
if a > b:
return 1
return 0
print sorted(['bob', 'about', 'Zoo', 'Credit'], cmp_ignore_case)
a = s1.capitalize()
b = s2.capitalize()
if a < b:
return -1
if a > b:
return 1
return 0
print sorted(['bob', 'about', 'Zoo', 'Credit'], cmp_ignore_case)
2017-07-29
def format_name(s):
return s.capitalize()
print map(format_name, ['adam', 'LISA', 'barT'])
return s.capitalize()
print map(format_name, ['adam', 'LISA', 'barT'])
2017-07-28
def calc_prod(lst):
def lazy_prod():
def prod(x, y):
z = x * y
return z
return reduce(prod, lst, 1)
return lazy_prod
f = calc_prod([1, 2, 3, 4])
print f()
def lazy_prod():
def prod(x, y):
z = x * y
return z
return reduce(prod, lst, 1)
return lazy_prod
f = calc_prod([1, 2, 3, 4])
print f()
2017-07-28
import time
def performance(unit):
def preformance_deco(f):
def _fn(*args,**kw):
print 'call %s() in %s%s' % (f.__name__,str(time.time()),unit)
return f(*args,**kw)
return _fn
return preformance_deco
def performance(unit):
def preformance_deco(f):
def _fn(*args,**kw):
print 'call %s() in %s%s' % (f.__name__,str(time.time()),unit)
return f(*args,**kw)
return _fn
return preformance_deco
2017-07-28
Ratinal(1, 2) 表示 1/2, p代表分子,q代表分母
任何一个有理数都可以用 分子/分母的形式表示
所以1/2 + 1/3 = (1*3+ 1*2) / 2*3
任何一个有理数都可以用 分子/分母的形式表示
所以1/2 + 1/3 = (1*3+ 1*2) / 2*3
2017-07-28
a, b = b, a + b
可能一眼会觉得是三步 a 和 b=b 和 a+b
其实是按中间等号映射
a=b 和 b = a+b
合在一起写就成了
a,b = b, a+b
java 程序员表示 python 真的很任性
可能一眼会觉得是三步 a 和 b=b 和 a+b
其实是按中间等号映射
a=b 和 b = a+b
合在一起写就成了
a,b = b, a+b
java 程序员表示 python 真的很任性
2017-07-28
import math
def is_sqr(x):
if math.sqrt(x) == int(math.sqrt(x)):
return x;
print filter(is_sqr, range(1, 101))
def is_sqr(x):
if math.sqrt(x) == int(math.sqrt(x)):
return x;
print filter(is_sqr, range(1, 101))
2017-07-28