您可以使用zip将字典与内容字符串配对,并为每个字符串设置“内容”键:
dicList = [{'url': 'https://test.com/find/city-1', 'tit': 'title1', 'val': 1},
{'url': 'https://test.com/find/city-2', 'tit': 'title1', 'val': 2},
{'url': 'https://test.com/find/city-3', 'tit': 'title1', 'val': 3}
]
contents = ['a','b','c']
for d,c in zip(dicList,contents):
d['content'] = c
print(dicList)
[{'url': 'https://test.com/find/city-1', 'tit': 'title1', 'val': 1, 'content': 'a'},
{'url': 'https://test.com/find/city-2', 'tit': 'title1', 'val': 2, 'content': 'b'},
{'url': 'https://test.com/find/city-3', 'tit': 'title1', 'val': 3, 'content': 'c'}]
或者,如果您希望结果出现在一个新的列表中,您可以使用列表理解来构建扩充字典:
dicList2 = [{**d, 'content':c} for d,c in zip(dicList,contents)]