Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #75444
| References | <CAFBK5a-hjukHaHOim4tL_RerXiHsFP03eaQoN42yGfeCJ9NZPg@mail.gmail.com> <lre4p7$ldu$1@ger.gmane.org> |
|---|---|
| From | Ian Kelly <ian.g.kelly@gmail.com> |
| Date | 2014-07-31 15:16 -0600 |
| Subject | Re: Dict when defining not returning multi value key error |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.12492.1406841464.18130.python-list@python.org> (permalink) |
On Thu, Jul 31, 2014 at 1:17 PM, Terry Reedy <tjreedy@udel.edu> wrote:
> On 7/31/2014 7:24 AM, Dilu Sasidharan wrote:
>
>> I am wondering why the dictionary in python not returning multi value
>> key error when i define something like
>>
>> p = {'k':"value0",'k':"value1"}
>
>
> This is documented behavior: "you can specify the same key multiple times in
> the key/datum list, and the final dictionary’s value for that key will be
> the last one given." I am not sure whether this is an accident of the
> initial design, never changed since, or intended for certain uses. It may
> partly be because this choice is slightly simpler or, since keys are
> expressions, not constants, that the check can only come at runtime.
I don't know either, but I think that it's generally expected that the
above would be equivalent to:
p = dict()
p['k'] = "value0"
p['k'] = "value1"
which of course will not throw an error since you're just updating the
value in that case.
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Dict when defining not returning multi value key error Ian Kelly <ian.g.kelly@gmail.com> - 2014-07-31 15:16 -0600
csiph-web