Skip to main content
 首页 » 编程设计

python之如何在 Python 中将 2 个列表放入 1 个字典中

2025年05月04日15xing901022

情况是这样的:我有 2 个列表,想将它们放入字典中。

内容 ['这是 Sams 的内容', '这是其他人的内容']
作者 ['Sam', 'Someone Else']

这是我要创建的字典

评论 [{'content': 'This is Sams Content', 'author' : 'Sam'} , {'content': 'This is someone's content', 'author' : 'Someone Else'} p>

我希望你明白问题是什么。感谢您的帮助。

请您参考如下方法:

我相信您正在寻找 zip。像这样:

reviews = [{'content': c, 'author': a} for c, a in zip(contentList, authorList)]