У меня есть три списка с несколькими словарями внутри.Объединить словари из нескольких списков в 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
Я использую питона 2.7.10
AttributeError: объект 'str' не имеет атрибутов 'items' является результатом вашего кода, кстати, я использую python2 –
@DeanChristianArmada Этот ответ предполагает проблему со списком слов, а не список-словаря, которые вы пытаетесь. – ppperry
@DeanChristianArmada Этот подход использует список словарей –