[New-bugs-announce] [issue44033] Adding multiple keys of the same name to a dict doesn't raise an exception

Shreyan Avigyan report at bugs.python.org
Tue May 4 12:51:35 EDT 2021


New submission from Shreyan Avigyan <shreyan.avigyan at gmail.com>:

Adding multiple keys of the same name to a dict should raise an exception but instead causes a different behavior. For example consider this code,

>>> d = {"x" : "First value", "x" : "Second value", "y" : "Third value"}

One would expect a error because there two keys with the same name or that Python will add "x" : "First value" and will skip "x" : "Second value". But the result is opposite,

>>> d
{'x': 'Second value', 'y': 'Third value'}

Is this a bug or is this an intended behavior? (I may have missed out information related to this in the documentation. Kindly correct me if that's the case.)

----------
messages: 392918
nosy: shreyanavigyan
priority: normal
severity: normal
status: open
title: Adding multiple keys of the same name to a dict doesn't raise an exception
type: behavior
versions: Python 3.10, Python 3.11, Python 3.9

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue44033>
_______________________________________


More information about the New-bugs-announce mailing list