ef performance(unit):
def pd(f):
@functools.wraps(f)
def w(x):
t1 = time.time()
r = f(x)
t2 = time.time()
t = (t2 - t1) * 1000 if unit == ms else (t2-t1)
print 'call %s() in %f %s' % (f.__name__, t, unit)
return r
return w
return pd
def pd(f):
@functools.wraps(f)
def w(x):
t1 = time.time()
r = f(x)
t2 = time.time()
t = (t2 - t1) * 1000 if unit == ms else (t2-t1)
print 'call %s() in %f %s' % (f.__name__, t, unit)
return r
return w
return pd
2016-07-18
判断整数的方法:int(x)==x; math.floor(x)==x; x%1==x; math.ceil(x)==x; round(x)==x
2016-07-16
myabs = lambda x: -x if x < 0 else x 這個表達式也是醉了
2016-07-16
def calc_prod(lst):
def mul():
return 1*2*3*4
return mul
f = calc_prod([1, 2, 3, 4])
print f()
def mul():
return 1*2*3*4
return mul
f = calc_prod([1, 2, 3, 4])
print f()
2016-07-15
def calc_prod(lst):
def lazy():
def prod(x,y):
return x * y
return reduce(prod,lst)
return lazy
f = calc_prod([1, 2, 3, 4])
print f()
def lazy():
def prod(x,y):
return x * y
return reduce(prod,lst)
return lazy
f = calc_prod([1, 2, 3, 4])
print f()
2016-07-15