def calc_prod(lst):
return lambda :reduce((lambda x,y: x*y),lst)
f = calc_prod([1, 2, 3, 4])
print f()
return lambda :reduce((lambda x,y: x*y),lst)
f = calc_prod([1, 2, 3, 4])
print f()
2016-05-02
import math
def is_sqr(x):
return math.sqrt(x)*10%10==0
print filter(is_sqr, range(1, 101))
def is_sqr(x):
return math.sqrt(x)*10%10==0
print filter(is_sqr, range(1, 101))
2016-04-29
def format_name(s):
return s[0].upper() + s[1:].lower()
print map(format_name, ['adam', 'LISA', 'barT'])
return s[0].upper() + s[1:].lower()
print map(format_name, ['adam', 'LISA', 'barT'])
2016-04-28
import math
def add(x, y, f):
return f(x) + f(y)
print add(25, 9, math.sqrt)
def add(x, y, f):
return f(x) + f(y)
print add(25, 9, math.sqrt)
2016-04-28
def format_name(s):
return s.title()
print map(format_name, ['adam', 'LISA', 'barT'])
return s.title()
print map(format_name, ['adam', 'LISA', 'barT'])
2016-04-28
def calc_prod(lst):
def g():
num = 1
for i in lst:
num *=i
return num
return g
f = calc_prod([1, 2, 3, 4])
print f()
def g():
num = 1
for i in lst:
num *=i
return num
return g
f = calc_prod([1, 2, 3, 4])
print f()
2016-04-27
import math
def is_sqr(x):
return x and math.sqrt(x) % 1 == 0
print filter(is_sqr, range(1, 101))
def is_sqr(x):
return x and math.sqrt(x) % 1 == 0
print filter(is_sqr, range(1, 101))
2016-04-27
def count():
fs = []
for i in range(1, 4):
def f(item=i):
return item * item
fs.append(f)
return fs
f1, f2, f3 = count()
print f1(), f2(), f3()
fs = []
for i in range(1, 4):
def f(item=i):
return item * item
fs.append(f)
return fs
f1, f2, f3 = count()
print f1(), f2(), f3()
2016-04-27
def cmp_ignore_case(s1, s2):
s1 = s1.upper()
s2 = s2.upper()
if s1 > s2:
return 1
elif s1 < s2:
return -1
else:
return 0
print sorted(['bob', 'about', 'Zoo', 'Credit'], cmp_ignore_case)
s1 = s1.upper()
s2 = s2.upper()
if s1 > s2:
return 1
elif s1 < s2:
return -1
else:
return 0
print sorted(['bob', 'about', 'Zoo', 'Credit'], cmp_ignore_case)
2016-04-26
def calc_prod(lst):
def prod(x,y):
return x*y
def lazy():
return reduce(prod,lst)
return lazy
f = calc_prod([1, 2, 3, 4])
print f()
def prod(x,y):
return x*y
def lazy():
return reduce(prod,lst)
return lazy
f = calc_prod([1, 2, 3, 4])
print f()
2016-04-26
初一看,不懂,仔细看之easy!
Rational(self.p * r.q + self.q * r.p, self.q * r.q)
来说:分子/分母
self第一个参数,r第二个参数
Rational(self.p * r.q + self.q * r.p, self.q * r.q)
来说:分子/分母
self第一个参数,r第二个参数
2016-04-25