def count():
fs = []
for i in range(1, 4):
def f(j):
def g():
return j*j
return g
r=f(i)
fs.append(r)
return fs
f1, f2, f3 = count()
print f1(), f2(), f3()
fs = []
for i in range(1, 4):
def f(j):
def g():
return j*j
return g
r=f(i)
fs.append(r)
return fs
f1, f2, f3 = count()
print f1(), f2(), f3()
2016-01-30
def calc_prod(lst):
def prod(x,y):
return x*y
def lazy_prod():
return reduce(prod,lst)
return lazy_prod
f = calc_prod([1, 2, 3, 4])
print f()
def prod(x,y):
return x*y
def lazy_prod():
return reduce(prod,lst)
return lazy_prod
f = calc_prod([1, 2, 3, 4])
print f()
2016-01-30
f1,f2,f3可以被调用,所以conut()的返回值是一个有函数组成的列表【f1,f2,f3】,f1()=1,f2()=4,f3()=9
所以fs.append(f)中的f的返回值应该对应成1,4,9 。不知理解的对不对
所以fs.append(f)中的f的返回值应该对应成1,4,9 。不知理解的对不对
2016-01-27
import math
def is_sqr(x):
n=math.sqrt(x)
return n%(1.0)==0
print filter(is_sqr, range(1, 101))
def is_sqr(x):
n=math.sqrt(x)
return n%(1.0)==0
print filter(is_sqr, range(1, 101))
2016-01-27