格式怎么都不对!马丹
def count():
fs = []
for i in range(1, 4):
def f(i):
return i * i
fs.append(f)
return fs
f1, f2, f3 = count()
print f1(1), f2(2), f3(3)
def count():
fs = []
for i in range(1, 4):
def f(i):
return i * i
fs.append(f)
return fs
f1, f2, f3 = count()
print f1(1), f2(2), f3(3)
2016-08-10
很简单:
def calc_prod(lst):
def calc_cheng():
return reduce(lambda x,y: x *y ,lst)
return calc_cheng
f = calc_prod([1, 2, 3, 4])
print f()
def calc_prod(lst):
def calc_cheng():
return reduce(lambda x,y: x *y ,lst)
return calc_cheng
f = calc_prod([1, 2, 3, 4])
print f()
2016-08-10
from __future__ import unicode_literals
s = u'am I an unicode?'
print isinstance(s, unicode)
不应该是b吗?str前面 - -
s = u'am I an unicode?'
print isinstance(s, unicode)
不应该是b吗?str前面 - -
2016-08-09
class Fib(object):
def __init__(self, num):
self.num = num
def __str__(self):
fib = lambda n:1 if n == 1 else ( 0 if n == 0 else fib(n-1) + fib(n-2))
return [fib(x) for x in range(10)].__str__()
__repr__ = __str__
def __len__(self):
return self.num
def __init__(self, num):
self.num = num
def __str__(self):
fib = lambda n:1 if n == 1 else ( 0 if n == 0 else fib(n-1) + fib(n-2))
return [fib(x) for x in range(10)].__str__()
__repr__ = __str__
def __len__(self):
return self.num
2016-08-09
如题,需要固定的函数为sorted,需要固定其比较函数cmp,这是其官方文档sorted(iterable[, cmp[, key[, reverse]]])
可知只需要修改cmp,则
sorted_ignore_case = functools.partial(sorted, cmp = cmpy)
#其中def cmpy(s1,s2):
if s1.lower()>s2.lower():
return 1
if s1.lower()<s2.lower():
return -1
PS:代码有点乱,有纰漏还请指出
可知只需要修改cmp,则
sorted_ignore_case = functools.partial(sorted, cmp = cmpy)
#其中def cmpy(s1,s2):
if s1.lower()>s2.lower():
return 1
if s1.lower()<s2.lower():
return -1
PS:代码有点乱,有纰漏还请指出
2016-08-08
是想到要定义个 read()函数了,连蒙带猜的,是不是该给自己点个赞。然而偷个懒没有把r''加上,结果愣是没出来,不明白咯。
2016-08-08