This issue tracker has been migrated to GitHub ,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
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) * (Python committer) | 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: + msg161499 |
| 2012年05月24日 10:41:02 | mark.dickinson | set | status: open -> closed nosy: + mark.dickinson messages: + msg161498 resolution: not a bug |
| 2012年05月24日 10:39:05 | sbermeister | set | type: behavior components: + Build versions: + Python 2.7 |
| 2012年05月24日 10:38:30 | sbermeister | create | |