python - 如何在 Python 中从多个列表创建字典

标签 python python-3.x

我想从多个列表创建一个字典。例如:

list1=[11, 12, 13, 14]
list2=[a, b, c, d]
list3=[e, f, g, h]

结果应该是:

dict={11: [a,e], 12:[b,f], 13:[c,g], 14:[d,h]}

谢谢

最佳答案

像这样:

obj = {}
for x,y,z in zip(list1,list2,list3):
    obj[x] = [y,z]

关于python - 如何在 Python 中从多个列表创建字典,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55325076/

相关文章:

python - 写入文件错误和权限错误

python - 在python中组合多个项目列表

python-3.x - 如何将每隔一行提取到数据框中的单独列中?

python - 如何将列表转换为字典?

python - Popen subprocess.PIPE 及其用途

python - 从 C 扩展代码中释放 python 列表

python - django spotify api python http发布500错误

python - 更新嵌套列表在 python 中花费的时间太长

python - 正确地将自己的功能应用于分组的 Pandas 数据框

python - 根据空间接近度对几何点进行分组