居然还有人说高阶函数相当于数学里的泛函,求别无知了行吗,你来学学泛函指不定挂科多少回,泛函是完全另一种理论。别误导大众了
2015-05-03
def calc_prod(lst):
def cal():
def f(x,y):
return x*y
return reduce(f,lst)
return cal
f = calc_prod([1, 2, 3, 4])
print f()
def cal():
def f(x,y):
return x*y
return reduce(f,lst)
return cal
f = calc_prod([1, 2, 3, 4])
print f()
2015-04-29
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))
2015-04-29
弱弱的问一句,def __add__(self, r):
return Rational(self.p * r.q + self.q * r.p, self.q * r.q)
里的r是干嘛的= =
return Rational(self.p * r.q + self.q * r.p, self.q * r.q)
里的r是干嘛的= =
2015-04-29
它给的答案里def __init__(self, num):
a, b, L = 0, 1, []
for n in range(num):
应该是def __init__(self, num):
a, b, L = 0, 1, []
for n in range(num+1):
如果没有+1会少一个
a, b, L = 0, 1, []
for n in range(num):
应该是def __init__(self, num):
a, b, L = 0, 1, []
for n in range(num+1):
如果没有+1会少一个
2015-04-29
def gcd(a,b):
if max(a,b)%min(a,b)==0:
return min(a,b)
else:
return gcd(min(a,b),max(a,b)%min(a,b))
if max(a,b)%min(a,b)==0:
return min(a,b)
else:
return gcd(min(a,b),max(a,b)%min(a,b))
2015-04-28
class Fib(object):
def __init__(self, num):
self.nums=[]
if num==1:
self.nums=[1]
else :
n=2
self.nums=[1,2]
while n<num:
self.nums.append(self.nums[n-1]+self.nums[n-2])
n=n+1
def __init__(self, num):
self.nums=[]
if num==1:
self.nums=[1]
else :
n=2
self.nums=[1,2]
while n<num:
self.nums.append(self.nums[n-1]+self.nums[n-2])
n=n+1
2015-04-28
import math
def is_sqr(x):
if math.sqrt(x) in range(1,11):
return x
print filter(is_sqr, range(1,101))
def is_sqr(x):
if math.sqrt(x) in range(1,11):
return x
print filter(is_sqr, range(1,101))
2015-04-27
def cmp_ignore_case(s1, s2):
if s1.lower()>s2.lower():
return 1
if s1.lower()<s2.lower():
return -1
return 0
if s1.lower()>s2.lower():
return 1
if s1.lower()<s2.lower():
return -1
return 0
2015-04-26