Message 317035 - Python tracker

Message317035

Author mark.dickinson
Recipients Janusz Harkot, mark.dickinson
Date 2018-05-18.15:26:48
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1526657208.99.0.682650639539.issue33572@psf.upfronthosting.co.za>
In-reply-to
Content
It's documented here: https://docs.python.org/3/library/stdtypes.html#mapping-types-dict

> Numeric types used for keys obey the normal rules for numeric
> comparison: if two numbers compare equal (such as 1 and 1.0) then 
> they can be used interchangeably to index the same dictionary entry.

Since False == 0, False and 0 are interchangeable as dictionary keys. Similarly for True and 1. Note that the dictionary you created only actually has two entries:

>>> dta = {False: 'false', True: 'true', 0: 'zero', 1: 'one'}
>>> dta
{False: 'zero', True: 'one'}

Though calling out numeric types in particular in the docs does feel a little odd to me: the rule is that *any* two hashable objects that compare equal should be interchangeable for the purposes of dictionary lookup (or set membership, come to that). There's nothing particularly special about numbers in this context.
History
Date User Action Args
2018-05-18 15:26:49mark.dickinsonsetrecipients: + mark.dickinson, Janusz Harkot
2018-05-18 15:26:48mark.dickinsonsetmessageid: <1526657208.99.0.682650639539.issue33572@psf.upfronthosting.co.za>
2018-05-18 15:26:48mark.dickinsonlinkissue33572 messages
2018-05-18 15:26:48mark.dickinsoncreate