GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — gh-77753: Add hash examples for set/dict by slateny · Pull Request #92549 · python/cpython Conversation
|
| >>> d = {False: 'false'} | ||
| >>> d[0] = 0 | ||
| >>> d | ||
| {False: 0} |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
| {False: 0} | |
| {False: 0} | |
| >>> {1: 'a', True: 'b'} | |
| {1: 'b'} |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| Note that as long as the objects have the same hash values, they are seen as | ||
| equivalent by sets:: | ||
|
|
||
| >>> {0, True, False, 1} |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Could you please add some of the types Terry listed in the issue too? I was frankly surprised at them (especially the Decimal and Fractions with the same hash value).
Maybe this would help:
| >>> {0, True, False, 1} | |
| >>> {0, True, False, 1, 0.0, 1.0} |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| Note that as long as the objects have the same hash values, they are seen as | ||
| equivalent by sets:: |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
It is not true.
>>> hash(1) == hash(2**61)
True
>>> {1, 2**61}
{1, 2305843009213693952}
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| This also means if two keys have the same hash values, they will map to the same | ||
| entry in the dictionary:: |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Same as above.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Besides making two flat-out incorrect statements, I also don't think this is very useful. The examples are cute but aren't relevant to most users of dicts and sets. Also, it isn't the sets or dicts themselves that give rise to these examples; instead, it is that numbers were intentionally designed to support cross-type equality comparisons and to follow the rule that equal values should have the same hashes. This is documented elsewhere. Thanks for the suggestion, but I'm marking it is closed as a low quality edit. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@rhettinger I understand that the examples on hashing isn't as useful, but does the When you mark it closed due to low quality, is it due to examples not thorough enough, wording too short, or something else? I would like to improve the docs so knowing what exactly can be changed other than the incorrectness would be helpful to me. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.