def calc_prod(lst):
def plus():
p=1
for x in lst:
p=p*x
return p
return plus
f = calc_prod([1, 2, 3, 4])
print f()
def plus():
p=1
for x in lst:
p=p*x
return p
return plus
f = calc_prod([1, 2, 3, 4])
print f()
2016-04-20
#coding=utf-8
def log(info):
def ww1(f):
def ww2(args):
print "[%s] 执行函数%s(),得出%s的平方为%s" %(info,f.__name__,args,f(args))
return ww2
return ww1
@log('DEBUG')
def f1(x):
aa = x*x
return aa
f1(5)
def log(info):
def ww1(f):
def ww2(args):
print "[%s] 执行函数%s(),得出%s的平方为%s" %(info,f.__name__,args,f(args))
return ww2
return ww1
@log('DEBUG')
def f1(x):
aa = x*x
return aa
f1(5)
2016-04-18
def cmp_ignore_case(s1, s2):
if s1[0].lower()>s2[0].lower():
return 1
if s1[0].lower()<s2[0].lower():
return -1
else:
return 0
print sorted(['bob', 'about', 'Zoo', 'Credit'], cmp_ignore_case)
if s1[0].lower()>s2[0].lower():
return 1
if s1[0].lower()<s2[0].lower():
return -1
else:
return 0
print sorted(['bob', 'about', 'Zoo', 'Credit'], cmp_ignore_case)
2016-04-17
import time, functools
def performance(unit):
def perf_decorator(f):
@functools.wraps(f)
def wrapper(*args, **kw):
print 'call'+ f.__name__ +'()...'
print str(time.time()) + '%s'%(unit)
return wrapper
return perf_decorator
def performance(unit):
def perf_decorator(f):
@functools.wraps(f)
def wrapper(*args, **kw):
print 'call'+ f.__name__ +'()...'
print str(time.time()) + '%s'%(unit)
return wrapper
return perf_decorator
2016-04-17
import time
def performance(unit):
def a(f):
def b(*args, **kwargs):
print 'call'+ f.__name__ +'()...'
print str(time.time()) + '%s'%(unit)
return f(*args, **kwargs)
return b
return a
def performance(unit):
def a(f):
def b(*args, **kwargs):
print 'call'+ f.__name__ +'()...'
print str(time.time()) + '%s'%(unit)
return f(*args, **kwargs)
return b
return a
2016-04-17
def calc_prod(lst):
def g():
resu = 1
for l in lst:
resu=resu*l
print resu
return resu
f = calc_prod([1, 2, 3, 4])
print f()
def g():
resu = 1
for l in lst:
resu=resu*l
print resu
return resu
f = calc_prod([1, 2, 3, 4])
print f()
2016-04-16
import math
def is_sqr(x):
return x % math.sqrt(x) == 0
print filter(is_sqr, range(1, 101))
def is_sqr(x):
return x % math.sqrt(x) == 0
print filter(is_sqr, range(1, 101))
2016-04-15