Python字典默认删除重复项(但我不想删除重复项)

时间:2016-04-06 13:02:14

标签: python dictionary hash duplicates

Python字典默认删除重复但我不想删除重复

程序

s = {"a":"s","a":"b","b":"d"}
print s

输出

{'a': 'b', 'b': 'd'}

预期的输出

{'a':'s','a':'b','b':'d'}

1 个答案:

答案 0 :(得分:1)

您应该考虑使用其他结构。字典是键值,因此每个键只有1个值。 尝试使用元组列表或dict中的每个键存储值列表。