Dict when defining not returning multi value key error

Dan Stromberg drsalists at gmail.com
Thu Jul 31 23:08:20 EDT 2014


On Thu, Jul 31, 2014 at 4:24 AM, Dilu Sasidharan <dilu.seven at gmail.com> wrote:
> Hi,
>
> I am wondering why the dictionary in python not returning multi value key
> error when i define something like
>
> p = {'k':"value0",'k':"value1"}
>
> key is string immutable and sometimes shares same id.
>
> also if the key is immutable and have different ids.
>
> like
>
> p = {'1':"value0",'1.0':"value1"}

If you want a dict that refuses to overwrite a key-value pair, you
could create one starting from
http://stackoverflow.com/questions/3387691/python-how-to-perfectly-override-a-dict
.  It's not an unreasonable behavior that you're looking for, but
neither is the actual behavior.

For 1 and 1.0 - they simply hash differently.  Dictionaries are
resizeable hash tables.



More information about the Python-list mailing list