python3中sorted函數和python2的使用方法不一樣,下面是python3的使用方法:
def cmp_ignore_case(x):
return x.upper()
print ( sorted(['bob', 'about', 'Zoo', 'Credit'], key = cmp_ignore_case) )
def cmp_ignore_case(x):
return x.upper()
print ( sorted(['bob', 'about', 'Zoo', 'Credit'], key = cmp_ignore_case) )
2020-07-24
def count():
fs = []
for i in range(1, 4):
def f(k=i):
return k*k
fs.append(f)
return fs
f1, f2, f3 = count()
print f1(), f2(), f3()
fs = []
for i in range(1, 4):
def f(k=i):
return k*k
fs.append(f)
return fs
f1, f2, f3 = count()
print f1(), f2(), f3()
2020-07-22
最新回答 / 芋頭戰士
allattr = dir(p)myattr = filter(lambda x: x[1] != '_', allattr) // 這里條件寫的比較簡陋print myattr
2020-07-22
def sqrt(x):
return x**0.5
def add(x, y, f):
return f(x) + f(y)
print add(25, 9, sqrt)
return x**0.5
def add(x, y, f):
return f(x) + f(y)
print add(25, 9, sqrt)
2020-07-21
最新回答 / 慕沐4009739
我覺得是這個路徑是系統編譯器的路徑,在運行程序的時候找不到該路徑,就報錯了。但是os.path.isdir,os.path.isfile 的使用是沒錯的。我也是新手,回答的不好請見諒
2020-07-20
已采納回答 / 慕粉1433321958
先了解一下sorted()函數, 語法如下
sorted(iterable,?cmp=None,?key=None,?reverse=False) iterable?--?可迭代對象。 cmp?--?比較的函數,這個具有兩個參數,參數的值都是從可迭代對象中取出,此函數必須...
2020-07-20
__init__(self, num):
self.num = num
self.l = []
a = 0
b = 1
for i in range(num):
self.l.append(a)
a = a + b
b = a - b
__str__(self):
return str(self.l)
__len__(self):
return len(self.l)
self.num = num
self.l = []
a = 0
b = 1
for i in range(num):
self.l.append(a)
a = a + b
b = a - b
__str__(self):
return str(self.l)
__len__(self):
return len(self.l)
2020-07-09
最新回答 / 吉吉chen
請回看2-5的reduce函數,return reduce(f,lst,1)這句話的意思是返回lazy_prod函數調用后的結果,calc_prod(lst)是一個接受list參數的函數,它里面包括定義lazy_prod函數并返回lazy_prod函數。如果calc_prod(lst)這個函數沒有被調用,那么這個函數不會進行參數乘積計算。
2020-07-03