Skip to content

Correct design.rst dictionaries section #11272

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions Doc/faq/design.rst
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,8 @@ times don't require an actual resize.
How are dictionaries implemented in CPython?
--------------------------------------------

CPython's dictionaries are implemented as resizable hash tables. Compared to
CPython's dictionaries are implemented as resizable
`hash tables <https://en.wikipedia.org/wiki/Hash_table>`_. Compared to
B-trees, this gives better performance for lookup (the most common operation by
far) under most circumstances, and the implementation is simpler.

Expand All @@ -499,9 +500,9 @@ using the :func:`hash` built-in function. The hash code varies widely depending
on the key and a per-process seed; for example, "Python" could hash to
-539294296 while "python", a string that differs by a single bit, could hash
to 1142331976. The hash code is then used to calculate a location in an
internal array where the value will be stored. Assuming that you're storing
keys that all have different hash values, this means that dictionaries take
constant time -- O(1), in Big-O notation -- to retrieve a key.
internal array where the value will be stored. In the average-case a dictionary
will take constant time -- O(1), in Big-O notation -- to retrieve a key, whereas
in the worst-case it will take linear time, or O(n).


Why must dictionary keys be immutable?
Expand Down