我有三個列表,裏面有多個字典。從Python中的多個列表中合併字典
list1 = [{'question': u'Fan offline information can be found on what Screen under General Menu? '}, {'question': u'What is the tool for F5 BIGIP to get packet traces. '}, {'question': u'On a HTTP Health Monitor configuration. If Receive string and Disabling string matched and Reverse is enabled. What would be the status of pool members?'}]
list2 = [{'answer': u'SysteminfoScreen'}, {'answer': u'qkview'}, {'answer': u'Offline'}]
list3 = [{'correct_answer': u'SysteminfoScreen'}, {'correct_answer': u'TCP Dump'}, {'correct_answer': u'Disabled'}]
如何將這三個列表合併爲一個類似於此的結果?
[{'question': u'What is the tool for F5 BIGIP to get packet traces. ', 'answer': u'qkview', 'correct_answer': u'TCP Dump'}]
另一種選擇,如果上述問題無法實現的情況
list1 = ['Fan offline information can be found on what Screen under General Menu? ', 'What is the tool for F5 BIGIP to get packet traces. ', 'On a HTTP Health Monitor configuration. If Receive string and Disabling string matched and Reverse is enabled. What would be the status of pool members?']
list2 = ['SysteminfoScreen', 'qkview', 'Offline']
list3 = ['SysteminfoScreen', 'TCP Dump', 'Disabled']
合併三成的相同的結果:
[{'question': u'What is the tool for F5 BIGIP to get packet traces. ', 'answer': u'qkview', 'correct_answer': u'TCP Dump'}]
PS
我使用python 2.7.10
AttributeError的:「海峽」對象有沒有屬性「項目」是你的代碼的結果是,我使用python2 –
@DeanChristianArmada這個答案是假設列表的-字典問題的方式,而不是列表OF-你正在嘗試的字符串。 – ppperry
@DeanChristianArmada此方法使用字典列表 –