1 回答

TA貢獻(xiàn)1874條經(jīng)驗(yàn) 獲得超12個(gè)贊
根據(jù)您的帖子,現(xiàn)有的列表結(jié)構(gòu)是:
list1
- 0
- 0 - [.....96......]
- 1 - [.....96......]
- 2 - [.....96......]
|
- 1
- 0 - [.....96......]
- 1 - [.....96......]
- 2 - [.....96......]
|
- 2
- 3
- 4
|
- 19
list2 - [.....96......]
目標(biāo)是:
復(fù)制list1到新列表
在新列表中,對于最低級別子列表中的每個(gè)元素,添加來自的匹配元素list2
此代碼應(yīng)該適用于此。
# create new list for totals
lstNew = copy.deepcopy(list1)
# process adds
for e1 in lstNew: # 20 elements
for e2 in e1: # each sublist
for i in range(len(e2)): # 96 elements
e2[i] += lists[i] # add element from list2
print(lstNew)
添加回答
舉報(bào)