def calc_prod(lst):
def prodxy():
return reduce(lambda x, y:x*y, lst)
return prodxy
f = calc_prod([1, 2, 3, 4])
print f()
def prodxy():
return reduce(lambda x, y:x*y, lst)
return prodxy
f = calc_prod([1, 2, 3, 4])
print f()
2016-03-13
import math
def f(x):
return math.sqrt(x)%1==0
print filter(f,range(1,101))
def f(x):
return math.sqrt(x)%1==0
print filter(f,range(1,101))
2016-03-12
最新回答 / neocosmos
两两比较的,这里的p1 p2只是参数,防止混淆可以写成更清楚:L2 = sorted(L1, lambda x,y:cmp(x.name,y.name))
2016-03-11
def calc_prod(lst):
def lazy_prod():
def f(x, y):
return x * y
return reduce(f, lst)
return lazy_prod
f = calc_prod([1, 2, 3, 4])
print f()
def lazy_prod():
def f(x, y):
return x * y
return reduce(f, lst)
return lazy_prod
f = calc_prod([1, 2, 3, 4])
print f()
2016-03-10
def calc_prod(lst):
def poly():
num = 1
for n in lst:
num *= n
return num
return poly
f = calc_prod([1, 2, 3, 4])
print f()
def poly():
num = 1
for n in lst:
num *= n
return num
return poly
f = calc_prod([1, 2, 3, 4])
print f()
2016-03-10
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-03-10
最赞回答 / 再见你
我想题主想问的是为什么下面这段代码没有进行延时处理吧?<...code...>对这个问题,我也想了半天,做了一些实验,实验得出结论应该是:python加载函数时是懒加载方式的,也就是说,当调...
2016-03-09