1樓:蓋世小猛男
all_list =
length1 = len(res_list)length2 = len(res_list2)if length1 < length2:
length = length2
elif length1 > length2:
length = length1
else:
length = length1
for i in range(length):
這種避免了缺少值。
2樓:靈劍
import
itertools
list
(itertools
.chain
.from_iterable
(zip(a
,b)))flatten在我這起碼慢十倍,還不相容Python3,畢竟人家是遞迴展平。
另一種等效的寫法是[rv
forr
inzip(a
,b)for
rvinr]
如果列表很大,可以把zip換成itertools.izip。Python3裡的zip就是izip,所以沒有izip這個函式了,要注意下
3樓:Yriuns
from
compiler.ast
import
flattena=
[1,2
,3,4
,5,6
]b=[
'a',
'b',
'c',
'd',
'e']c=
flatten
(zip(a
,b))printc[
1,'a',2,
'b',3,
'c',4,
'd',5,
'e']
Python3如何實現兩個列表的交叉列印?
defiter cross iterables copy iter item for item initerables while copy 一直迭代到copy列表為空 foritem incopy try yield next item except StopIteration 如果next 丟擲...
php 如何實現待辦記事列表
奧古斯巨集 在我這個邏輯中,都沒用到定時任務.進入頁面的時候執行相關邏輯就可以.不過你的最好是使用定時任務,你擔心的是每天執行一遍,每天都會查詢大量的資料 或者說會查出大量的資料,感覺沒必要 這裡有兩個資料量問題,第乙個是儲存的資料量,第二個是查詢的資料量.儲存的資料量沒法優化,但是第二個查詢的資料...
Python如何判斷列表元素嚴格遞增?
Beviniy 提供一種效率更高的方案 all a i a i 1 for i in range len a 1 原答案sorted a a and len set a len a defjudge alist if any alist i 1 alist i foriin range 0 len ...