keying by identity in dict and set

Paul Moore p.f.moore at gmail.com
Mon Oct 28 06:12:50 EDT 2019


On Mon, 28 Oct 2019 at 10:01, Steve White <stevan.white at gmail.com> wrote:
>
> Hi Chris,
>
> I'm afraid you've missed my point.  As I said in the initial post, I
> have read the documentation.
>
> I think the documentation does not adequately explain how the
> hashtable (or hashtables generally) work internally.

As stated in the docs, "The only required property is that objects
which compare equal have the same hash value". The docs do *not*
explain how dictionaries work internally, and that's deliberate. You
should not rely on the internal workings of dictionaries, because your
code may then not work on other Python implementations (or even on
later versions of CPython).

Of course, if you're only interested in working on CPython, then you
can rely on the details of the dictionary implementation, but in that
case you;re expected to look at the implementation (and be prepared
for it to change over time!)

Paul



More information about the Python-list mailing list