def performance(f):
def fn(x):
start = time.time()
r = f(x)
print r
print "call " + f.__name__ + "() in:" + str(time.time() - start)
return fn
@performance
def factorial(n):
return reduce(lambda x,y: x*y, range(1, n+1))
print factorial(10)
def fn(x):
start = time.time()
r = f(x)
print r
print "call " + f.__name__ + "() in:" + str(time.time() - start)
return fn
@performance
def factorial(n):
return reduce(lambda x,y: x*y, range(1, n+1))
print factorial(10)
2015-12-22
def count():
fs = []
for i in range(1, 4):
def m(a = i):
return a*a
fs.append(m)
return fs
f1, f2, f3 = count()
print f1(), f2(), f3()
fs = []
for i in range(1, 4):
def m(a = i):
return a*a
fs.append(m)
return fs
f1, f2, f3 = count()
print f1(), f2(), f3()
2015-12-22
def cmp_ignore_case(s1, s2):
if s1[0].upper()>s2[0].upper():
return 1
return -1
print sorted(['bob', 'about', 'Zoo', 'Credit'], cmp_ignore_case)
if s1[0].upper()>s2[0].upper():
return 1
return -1
print sorted(['bob', 'about', 'Zoo', 'Credit'], cmp_ignore_case)
2015-12-21
def count():
fs = []
a = 1
b = 2
c = 3
def f1():
return a*a
def f2():
return b*b
def f3():
return c*c
fs.append(f1)
fs.append(f2)
fs.append(f3)
return fs
f1, f2, f3 = count()
print f1(), f2(), f3()
haha ,不要笑。。。。。。。
fs = []
a = 1
b = 2
c = 3
def f1():
return a*a
def f2():
return b*b
def f3():
return c*c
fs.append(f1)
fs.append(f2)
fs.append(f3)
return fs
f1, f2, f3 = count()
print f1(), f2(), f3()
haha ,不要笑。。。。。。。
2015-12-19