如何将两个dict列表连接到单个dict列表

时间:2018-05-03 05:07:47

标签: python

我是python的新手。

我有几个dict列表。我只想创建一个单词列表。

列表1:

[{'mnemonic': u'VERS', 'value': '2.0', 'unit': u'', 'description': u'CWLS LOG ASCII STANDARD - VERSION 2.0'}, 
{'mnemonic': u'WRAP', 'value': 'NO', 'unit': u'', 'description': u'ONE LINE PER DEPTH STEP'}]

列表2:

[{'mnemonic': u'STRT', 'value': '3122.0', 'unit': u'FT', 'description': u'START DEPTH'}, 
{'mnemonic': u'STOP', 'value': '4968.0', 'unit': u'FT', 'description': u'STOP DEPTH'}]

1 个答案:

答案 0 :(得分:1)

你要做的是整理两个列表,这可以通过python中的+运算符完成,如下所示:

list1 = [{'mnemonic': u'VERS', 'value': '2.0', 'unit': u'', 'description': u'CWLS LOG ASCII STANDARD - VERSION 2.0'}, {'mnemonic': u'WRAP', 'value': 'NO', 'unit': u'', 'description': u'ONE LINE PER DEPTH STEP'}]
list2 = [{'mnemonic': u'STRT', 'value': '3122.0', 'unit': u'FT', 'description': u'START DEPTH'}, {'mnemonic': u'STOP', 'value': '4968.0', 'unit': u'FT', 'description': u'STOP DEPTH'}]

list3 = list1 + list2