A bit weird dictionary behavior

Arnaud Delobelle arnodel at googlemail.com
Mon Sep 22 11:52:39 CEST 2008


On 22 Sep, 10:25, "Pekka Laukkanen" <p... at iki.fi> wrote:
> Hello,
>
> just noticed this:
>
> Python 2.5.1 (r251:54863, Jan 17 2008, 19:35:17)
> [GCC 4.0.1 (Apple Inc. build 5465)] on darwin
> Type "help", "copyright", "credits" or "license" for more information.>>> {1: 2}
> {1: 2}
> >>> {True: False}
> {True: False}
> >>> {1: 2, True: False}
>
> {1: False}
>
> This must be because
>
> >>> True == 1 and True in {1: 2}
>
> True

That's exactly the reason!

> but it still doesn't feel exactly right. Would it be worth submitting a bug?

I don't think it can be considered as a bug, for the reason you gave
above and because dictionary keys are by definition unique with
respect to equality.

Perhaps you could call it a "surprising feature" :)

--
Arnaud



More information about the Python-list mailing list