Dict when defining not returning multi value key error

Ned Batchelder ned at nedbatchelder.com
Thu Jul 31 21:35:09 EDT 2014


On 7/31/14 5:15 PM, Ian Kelly wrote:
> On Thu, Jul 31, 2014 at 5: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"}
>
> In this latter case note that '1' and '1.0' are not equal, so this
> will simply result in two separate entries in the dict anyway.
>

You might want to check first:

     Python 2.7.5 (default, Aug  5 2013, 19:47:08)
     >>> 1 == 1.0
     True
     >>> {1.0: None, 1: None}
     {1.0: None}

-- 
Ned Batchelder, http://nedbatchelder.com




More information about the Python-list mailing list