Python 无法遍历列表以创建密钥对

Python 无法遍历列表以创建密钥对,python,dictionary,key-value,Python,Dictionary,Key Value,我试图用一个密钥对迭代和映射列表。我得到如下输出(即)我只得到列表中的最后一个值 {'first': [{'Key': 'Created', 'Value': '2020'}, {'Key': 'Type', 'Value': 'Entr'}], 'Second': [{'Key': 'Created', 'Value': '2020'}, {'Key': 'Type', 'Value': 'Entr'}]} 代码 tags=[[{'Key':'Created','Value':'2019'}

我试图用一个密钥对迭代和映射列表。我得到如下输出(即)我只得到列表中的最后一个值

{'first': [{'Key': 'Created', 'Value': '2020'}, {'Key': 'Type', 'Value': 'Entr'}], 'Second': [{'Key': 'Created', 'Value': '2020'}, {'Key': 'Type', 'Value': 'Entr'}]}
代码

tags=[[{'Key':'Created','Value':'2019'},{'Key':'Type','Value':'Business'}],{'Key':'Created','Value':'2020'},{'Key':'Type','Value':'Entr'}]
samplelist=['first','Second']
sampledict={}
对于样本列表中的i:
对于标记中的标记:
sampledict[i]=标签
预期产出

{'first': [{'Key': 'Created', 'Value': '2019'}, {'Key': 'Type', 'Value': 'Business'}], 'Second': [{'Key': 'Created', 'Value': '2020'}, {'Key': 'Type', 'Value': 'Entr'}]}
tags=[[{'Key':'Created','Value':'2019'},
{'Key':'Type','Value':'Business'}],
[{'Key':'Created','Value':'2020'},
{'Key':'Type','Value':'Entr'}]]
samplelist=['first','Second']
sampledict={}
i=0
而i
您可以按如下方式使用dict和zip组合:

dict(zip(samplelist, tags))
注意:您可能不知道这一点,但您缺少一个报价符号。标签应如下所示:

tags = [[{'Key': 'Created', 'Value': '2019'}, {'Key': 'Type', 'Value': 'Business'}], [{'Key': 'Created', 'Value': '2020'}, {'Key': 'Type', 'Value': 'Entr'}]]
tags = [[{'Key': 'Created', 'Value': '2019'}, {'Key': 'Type', 'Value': 'Business'}], [{'Key': 'Created', 'Value': '2020'}, {'Key': 'Type', 'Value': 'Entr'}]]