Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #75435 > unrolled thread
| Started by | Terry Reedy <tjreedy@udel.edu> |
|---|---|
| First post | 2014-07-31 15:17 -0400 |
| Last post | 2014-07-31 15:17 -0400 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Dict when defining not returning multi value key error Terry Reedy <tjreedy@udel.edu> - 2014-07-31 15:17 -0400
| From | Terry Reedy <tjreedy@udel.edu> |
|---|---|
| Date | 2014-07-31 15:17 -0400 |
| Subject | Re: Dict when defining not returning multi value key error |
| Message-ID | <mailman.12483.1406834293.18130.python-list@python.org> |
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.
>>> def f(x): return 0
>>> {f(1):1, f(2):2}
{0: 2}
--
Terry Jan Reedy
Back to top | Article view | comp.lang.python
csiph-web