[Python-3000] Detecting conflicts in dict displays
Aaron Bingham
bingham at cenix-bioscience.com
Fri Jul 14 16:03:28 CEST 2006
Fredrik Lundh wrote:
>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 )
>
>
Thanks for the clarification. That is reassuring. Of course, this may
not do what was intended under certain circumstances, but at least the
behavior is well defined.
Regards,
--
--------------------------------------------------------------------
Aaron Bingham
Senior Software Engineer
Cenix BioScience GmbH
--------------------------------------------------------------------
More information about the Python-3000
mailing list