Issue 14898: Dict collision on boolean and integer values (original) (raw)
Issue14898
Created on 2012-05-24 10:38 by sbermeister, last changed 2022-04-11 14:57 by admin. This issue is now closed.
Messages (3) | ||
---|---|---|
msg161497 - (view) | Author: Sasha B (sbermeister) | Date: 2012-05-24 10:38 |
Not sure if this is predicted behaviour, but if I make a dict like: >>> x = {0: 'bar', True: 'foo'} and modify True with 1, or 0 with False: >>> x[False] = 'boo' >>> x[1] = 'far' the modifications happen: >>> x {0: 'boo', True: 'far'} Is this expected behaviour? It seems that the hashes for 'False' and 0 are confused, as are the hashes for 'True' and 1. | ||
msg161498 - (view) | Author: Mark Dickinson (mark.dickinson) * ![]() |
Date: 2012-05-24 10:41 |
Thanks for the report. Yes, this is expected. Dictionary membership is based on equality of keys. Since True and 1 are equal, only one of them can be present in a dictionary at a time (and a key lookup works with either). >>> x = {0: 'bar'} >>> x[0] 'bar' >>> x[False] 'bar' >>> x[0.0] 'bar' >>> 0 == False True | ||
msg161499 - (view) | Author: Sasha B (sbermeister) | Date: 2012-05-24 10:48 |
Ahh, I see. You are correct. Thanks. |
History | |||
---|---|---|---|
Date | User | Action | Args |
2022-04-11 14:57:30 | admin | set | github: 59103 |
2012-05-24 10:48:47 | sbermeister | set | messages: + |
2012-05-24 10:41:02 | mark.dickinson | set | status: open -> closednosy: + mark.dickinsonmessages: + resolution: not a bug |
2012-05-24 10:39:05 | sbermeister | set | type: behaviorcomponents: + Buildversions: + Python 2.7 |
2012-05-24 10:38:30 | sbermeister | create |