Python Dictionary Implementation Question

twitter logo github logo ・1 min read

I'm curious about the implementation of dictionary in python. I'm learning about hash tables in my computer science course, and I'm aware that the dictionary data structure in python works as a hash table.
What I haven't worked out is this: what determines the number of buckets in the hash table? I'm asking this about python dictionary in particular, although I'd be interested in other cases as well.


twitter logo DISCUSS (5)
markdown guide

I don't have a link at the moment, but I vaguely remember some Python core contributors doing deep dives into code on video quite a while back. That may not be helpful. πŸ€·πŸ½β€β™‚οΈ I'll see if I can find it.

Meanwhile, the docs have this to say:

And the follow-up might have some more info:

Here's a stackOverflow answer that, if not fully answering your question, will probably at least give you enough leads to get the answers you're looking for:

πŸ‘†πŸ½πŸ‘†πŸ½πŸ‘†πŸ½ That SO post actually links to Python source code, which is obviously the "one true" answer about it's implementation, if you are so inclined do dig in in such a way =)


Probably is the video you seek.

And PLEASE: refer to Does it make sense to refer to the documentation of a language that will become unsupported in 42 days? (And, more to the point, has an outdated implementation of dictionaries.)


Thanks for pointing that out. I'm well aware of Python2's EOL. I think providing a few good leads for someone looking for answers was a kind thing to do.

I doubt Python2's implementation is dangerous to the extent that it's harmful to share what I did. Please be careful to build on other's answers, instead of discouraging folks from trying to drop a few leads.

I acknowledge that if I had directly provided links to source, it would have been better that they were more up-to-date sources. I wasn't in a position to do that, so gave what I had.

That's not the specific video, but it's probably a better example than the one I remember. So thanks for pointing that one out! ;)

It is much better to provide links and things to Python 3.x resources, for sure!

Not dangerous, just useless (in the context). I can't see how changing 2 to 3 in that url could be perceived as so hard to do.


Good call Tommy. Aside from those resources (and their Python 3 versions), I found this post very helpful:

Classic DEV Post from Apr 4

Design Patterns in Java

I thought it would be a fun to write a series of blog posts looking at differen...

Erik Kristofer Anderson profile image
Former Chemist , Current Student , Future Data Engineer

Still don't have a account? You're welcome to lurk, but it's better to be part of the community.

Sign up now ❀️