def calc_prod(lst):
def prod():
return reduce(lambda x,y:x*y,lst)
return prod
f = calc_prod([1, 2, 3, 4])
print f()
def prod():
return reduce(lambda x,y:x*y,lst)
return prod
f = calc_prod([1, 2, 3, 4])
print f()
2016-08-01
def cmp_ignore_case(s1, s2):
if s1.lower() < s2.lower():
return -1
if s1.lower() > s2.lower():
return 1
return 0
print sorted(['bob', 'about', 'Zoo', 'Credit'], cmp_ignore_case)
if s1.lower() < s2.lower():
return -1
if s1.lower() > s2.lower():
return 1
return 0
print sorted(['bob', 'about', 'Zoo', 'Credit'], cmp_ignore_case)
2016-07-31
一、
import math
def is_sqr(x):
return x in [i**2 for i in range(1,11)]
print filter(is_sqr, range(1, 101))
二、def is_sqr(x):
return [x for i in range(1,11) if x==i**2]
print filter(is_sqr, range(1, 101))
import math
def is_sqr(x):
return x in [i**2 for i in range(1,11)]
print filter(is_sqr, range(1, 101))
二、def is_sqr(x):
return [x for i in range(1,11) if x==i**2]
print filter(is_sqr, range(1, 101))
2016-07-31
def format_name(s):
return s.capitalize()
print map(format_name, ['adam', 'LISA', 'barT'])
return s.capitalize()
print map(format_name, ['adam', 'LISA', 'barT'])
2016-07-31
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-07-31
def __str__(self):
return '(Student:%s,%s,%s)'%(self.name,self.gender,self.score)
s = Student('Bob', 'male', 88)
print s
return '(Student:%s,%s,%s)'%(self.name,self.gender,self.score)
s = Student('Bob', 'male', 88)
print s
2016-07-30