print filter(lambda s:s and len(s.strip()) > 0, ['test', None, '', 'str', ' ', 'END'])
2016-04-03
def calc_prod(lst):
def prod():
result = 1
for item in lst:
result = result * item
return result
return prod
f = calc_prod([1, 2, 3, 4])
print f()
def prod():
result = 1
for item in lst:
result = result * item
return result
return prod
f = calc_prod([1, 2, 3, 4])
print f()
2016-04-03
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-04-03
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-03
def prod(x, y):
return x*y
print reduce(prod, [2, 4, 5, 7, 12])
so easy!!!
return x*y
print reduce(prod, [2, 4, 5, 7, 12])
so easy!!!
2016-04-03
def prod(x,y):
return x*y
def calc_prod(lst):
def calc_list():
return reduce(prod,lst)
return calc_list
f = calc_prod([1, 2, 3, 4])
print f()
return x*y
def calc_prod(lst):
def calc_list():
return reduce(prod,lst)
return calc_list
f = calc_prod([1, 2, 3, 4])
print f()
2016-04-03
http://www.liaoxuefeng.com/wiki/001374738125095c955c1e6d8bb493182103fac9270762a000/001386820062641f3bcc60a4b164f8d91df476445697b9e000 可结合这个看看
2016-04-03
def __cmp__(self, s):
if self.score > s.score:
return -1
elif self.score < s.score:
return 1
else:
return -cmp(self.name,self.score)
if self.score > s.score:
return -1
elif self.score < s.score:
return 1
else:
return -cmp(self.name,self.score)
2016-04-03