import math
def is_sqr(x):
r = int(math.sqrt(x))
return r*r==x
print (list(filter(is_sqr, range(1, 101))))
def is_sqr(x):
r = int(math.sqrt(x))
return r*r==x
print (list(filter(is_sqr, range(1, 101))))
2018-04-18
import math
def is_sqr(x):
r = int(math.sqrt(x))
return r*r==x
print filter(is_sqr, range(1, 101))
def is_sqr(x):
r = int(math.sqrt(x))
return r*r==x
print filter(is_sqr, range(1, 101))
2018-04-18
复杂一些但新手比较容易理解
import functools
sorted_ignore_case = functools.partial(sorted, cmp=lambda x,y : cmp(x.lower(),y.lower()))
print sorted_ignore_case(['bob', 'about', 'Zoo', 'Credit'])
import functools
sorted_ignore_case = functools.partial(sorted, cmp=lambda x,y : cmp(x.lower(),y.lower()))
print sorted_ignore_case(['bob', 'about', 'Zoo', 'Credit'])
2018-04-18
def calc_prod(lst):
def prod(x, y):
return x*y
def calc():
return reduce(prod, lst)
return calc
f = calc_prod([1, 2, 3, 4])
print f()
def prod(x, y):
return x*y
def calc():
return reduce(prod, lst)
return calc
f = calc_prod([1, 2, 3, 4])
print f()
2018-04-18
from functools import reduce
def prod(x, y):
return x*y
print (reduce(prod, [2, 4, 5, 7, 12]))
def prod(x, y):
return x*y
print (reduce(prod, [2, 4, 5, 7, 12]))
2018-04-18
阻挡我们学习代码的不是思维而是翻译,什么叫闭包,我的感觉叫“越权行为”都更加直观(翻译不好请多指正),匿名就更离谱了,是我们熟悉的匿名的意思吗,叫“裸体”函数都直观一些
2018-04-17
def cmp_ignore_case(s1, s2):
return ((s1.lower() > s2.lower()) - (s1.lower() < s2.lower()))
print sorted(['bob', 'about', 'Zoo', 'Credit'], cmp_ignore_case)
return ((s1.lower() > s2.lower()) - (s1.lower() < s2.lower()))
print sorted(['bob', 'about', 'Zoo', 'Credit'], cmp_ignore_case)
2018-04-17
class BStudent(Student,BasketballMixin):
def __init__(self):
Student.__init__(self)
BasketballMixin.__init__(self)
class FTeacher(Teacher,FootballMixin):
def __init__(self):
Teacher.__init__(self)
FootballMixin.__init__(self)
这样就行啦,先去看他的实例,怎么能让实例的方法执行
def __init__(self):
Student.__init__(self)
BasketballMixin.__init__(self)
class FTeacher(Teacher,FootballMixin):
def __init__(self):
Teacher.__init__(self)
FootballMixin.__init__(self)
这样就行啦,先去看他的实例,怎么能让实例的方法执行
2018-04-14