Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
假设我有
hand={"a":"2","p":"3","l":"1","e":"1","a":"13"}
如果我使用del["a"]它会删除所有事件,但如何只删除一个事件?
del["a"]
字典中没有任何键出现两次。字典不是这样工作的:任何键在字典中只能存在一次。
所以del将删除单次出现的"a".
del
"a"
您实际上不能在 Python 中存储多个相同类型的键,所以……抱歉。
Dict在 python 中不支持重复键。想象一下,您需要使用键访问特定值。如果有两个值与相关键关联,您将如何访问它?
Dict
您可以根据密钥存储列表。喜欢{'a': [1, 2]}
{'a': [1, 2]}