【发布时间】:2015-06-13 02:01:24
【问题描述】:
试图将列表转换为字典,但无法获得预期的输出
p = {}
a = ["s","l","y"]
for s in a:
p["size"] = s
print(p)
输出:
{'size': 'y'}
但我期待这样的输出
{'size': 's','size': 'l','size': 'y'}
我如何在 python 中实现这一点
【问题讨论】:
-
不行,
dict键应该是唯一的 -
是的,这不会像 itzmeontv 所说的那样起作用。你想用这些数据做什么?
-
假设你有你想要创建的字典
p,你做了p['size']。你想发生什么? -
如果我的回答回答了你的问题。请考虑接受它。谢谢!
标签: python arrays hash converter