[Python-3000] Detecting conflicts in dict displays
Fredrik Lundh
fredrik at pythonware.com
Thu Jul 13 16:40:23 CEST 2006
Guido van Rossum wrote:
>> Wouldn't the behavior of the above be undefined for the case where a ==
>> b? I'd much rather get an exception than undefined behavior.
>
> There's nothing undefined in the language currently about {a: 1, b:
> 2}. It creates an empty dict d, and then does d[a] = 1; d[b] = 2. If a
> and b are equal, you end up with {a: 2}.
for the formal definition, see "dictionary displays" in the language reference:
The key/datum pairs are evaluated from left to right to define the
entries of the dictionary: each key object is used as a key into the
dictionary to store the corresponding datum. /.../
Clashes between duplicate keys are not detected; the last datum
(textually rightmost in the display) stored for a given key value pre-
vails.
( http://pyref.infogami.com/dictionary-displays )
</F>
More information about the Python-3000
mailing list