我的字典2 Python列表:Python列表通過循環(更新)
[
{'index':'1','color':'red'},
{'index':'2','color':'blue'},
{'index':'3','color':'green'}
]
和
[
{'device':'1','name':'x'},
{'device':'2','name':'y'},
{'device':'3','name':'z'}
]
我如何可以追加每個字典從第二個列表的第一列表,以便以獲得輸出爲:
[
{'device':'1','name':'x','index': '1', 'color': 'red'},
{'device':'1','name':'x','index': '2', 'color': 'blue'},
{'device':'1','name': 'x','index': '3', 'color': 'green'}
{'device':'2','name':'y''index': '1', 'color': 'red'},
{'device':'2','name':'y','index': '2', 'color': 'blue'},
{'device':'2','name':'y','index': '3', 'color': 'green'}
{'device':'3','name':'z','index': '1', 'color': 'red'},
{'device':'3','name':'z','index': '2', 'color': 'blue'},
{'device':'3','name':'z','index': '3', 'color': 'green'}
]
其中做'device'鍵在結果列表中的第二和第三個字符上? –
爲什麼總共有6個詞典在輸入中,9個在輸出中?一些字典看起來合併了,但設備密鑰只在其中一個輸出字典中出現? – citizen2077
爲什麼輸出是「列表清單」? –