3 回答

TA貢獻1906條經(jīng)驗 獲得超3個贊
您的代碼非常易讀,我不會更改它。
通過列表理解,您可以編寫如下內(nèi)容:
for index, row in enumerate([row for row in listSchedule if row[0] == 'Download']): row[3] = myOtherList[index]

TA貢獻1963條經(jīng)驗 獲得超6個贊
您可以嘗試這樣做,但復制 otherlist 以免丟失信息:
[row+[myotherlist.pop(0)] if row[0]=='Download' else row for row in listScheduel]
例如:
list = [['Download',1,2,3],[0,1,2,3],['Download',1,2,3],['Download',1,2,3]]
otherlist = [0,1,2,3,4]
l = [ row+[otherlist.pop(0)] if row[0]=='Download' else row for row in list]
輸出:
[['Download', 1, 2, 3, 0],
[0, 1, 2, 3],
['Download', 1, 2, 3, 1],
['Download', 1, 2, 3, 2]]

TA貢獻1856條經(jīng)驗 獲得超17個贊
我們可以使用一個隊列,當滿足條件時將其值一一彈出。為了避免復制數(shù)據(jù),讓我們將隊列實現(xiàn)為myOtherList使用迭代器的視圖(感謝ShadowRanger)。
queue = iter(myOtherList)
for row in listSchedule:
if row[0] == "Download":
row.append(next(iter))
添加回答
舉報