print filter(lambda s: s and len(s.strip()) > 0, ['test', None, '', 'str', ' ', 'END'])
2016-05-21
def calc_prod(lst):
def f(x, y):
return x * y
def chengji():
return reduce(f, lst)
return chengji
fun = calc_prod([1, 2, 3, 4])
print fun()
def f(x, y):
return x * y
def chengji():
return reduce(f, lst)
return chengji
fun = calc_prod([1, 2, 3, 4])
print fun()
2016-05-21
def count():
fs = []
for i in range(1, 4):
def f():
return i*i
fs.append(f())
return fs
f1, f2, f3 = count()
print f1,f2,f3
fs = []
for i in range(1, 4):
def f():
return i*i
fs.append(f())
return fs
f1, f2, f3 = count()
print f1,f2,f3
2016-05-20
我的代码在我这里执行结果是24。
在这里死活通不过。
def calc_prod(lst):
def f1(x,y):
return x*y
def f():
return reduce(f1,lst)
return f
f = calc_prod([1, 2, 3, 4])
print f()
在这里死活通不过。
def calc_prod(lst):
def f1(x,y):
return x*y
def f():
return reduce(f1,lst)
return f
f = calc_prod([1, 2, 3, 4])
print f()
2016-05-20
class Person(object):
def __init__(self, name, gender, birth,**a):
self.name = name
self.gender = gender
self.birth = birth
for k,v in a.iteritems():
setattr(self,k,v)
xiaoming = Person('Xiao Ming', 'Male', '1990-1-1', job='Student')
print
def __init__(self, name, gender, birth,**a):
self.name = name
self.gender = gender
self.birth = birth
for k,v in a.iteritems():
setattr(self,k,v)
xiaoming = Person('Xiao Ming', 'Male', '1990-1-1', job='Student')
2016-05-20
def __cmp__(self, s):
if self.score < s.score:return 1
elif self.score > s.score:return -1
else:
if self.name <s.name:return -1
elif self.name > s.name: return 1
else:return 0
要死了 cmp()和-cmp() 两个函数居然没有想到
if self.score < s.score:return 1
elif self.score > s.score:return -1
else:
if self.name <s.name:return -1
elif self.name > s.name: return 1
else:return 0
要死了 cmp()和-cmp() 两个函数居然没有想到
2016-05-20
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-05-20
def calc_prod(lst):
def lazy():
def f(x,y):
return x*y
return reduce(f,lst)
return lazy
f = calc_prod([1, 2, 3, 4])
print f()
有点不懂lazy()存在的意义。。。
def lazy():
def f(x,y):
return x*y
return reduce(f,lst)
return lazy
f = calc_prod([1, 2, 3, 4])
print f()
有点不懂lazy()存在的意义。。。
2016-05-19
super(Teacher,self).__init__(name,gender)和Person.__init__(self,name,gender)等价的 二者选一就好
2016-05-19
def calc_prod(lst):
def ji(x,y):
return x*y
def fanhui():
return reduce(ji,lst)
return fanhui
f = calc_prod([1, 2, 3, 4])
print f()
def ji(x,y):
return x*y
def fanhui():
return reduce(ji,lst)
return fanhui
f = calc_prod([1, 2, 3, 4])
print f()
2016-05-18
这一期的内容:
1.任务没有足够的提示和详细的要求,导致结果经常不符合要求;
2.教学并没有承前启后,而且是跳跃的,答案会冒出没讲过得。
就这两个把我快逼疯了,超想骂人啊……
1.任务没有足够的提示和详细的要求,导致结果经常不符合要求;
2.教学并没有承前启后,而且是跳跃的,答案会冒出没讲过得。
就这两个把我快逼疯了,超想骂人啊……
2016-05-18