我有兩個詞典如下所示。我在Python 2.7。如何合併兩個詞典與多個鍵值對
entries_per_day = [ {"time": "October 1", "entries": "5" },
{"time": "October 2", "entries": "3" },
{"time": "October 3", "entries": "1" },
{"time": "October 4", "entries": "0" },
{"time": "October 5", "entries": "23" }]
views_per_day = [ {"time": "October 1", "views": "9" },
{"time": "October 2", "views": "3" },
{"time": "October 3", "views": "5" },
{"time": "October 4", "views": "6" },
{"time": "October 5", "views": "32" }]
我如何合併兩個庫到第3,使輸出看起來像這樣:
area_chart_data = [ {"time": "October 1", "entries": "5", "views": "9" },
{"time": "October 2", "entries": "3", "views": "3" },
{"time": "October 3", "entries": "1", "views": "5" },
{"time": "October 4", "entries": "0", "views": "6" },
{"time": "October 5", "entries": "23", "views": "32" }]
我想要的「項」和「意見」的鍵值對是在與最初使用日期相同的數據段。
他們不是2個字典,他們是2個列表,每個列表包含多個字典。 – Haris
你有沒有工作的嘗試?如果是這樣,請將其與其輸出(或其生成的例外)一起包含在問題中。 – glibdud
是總是排序的字典列表,如示例中所示? – murphy