TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Python Dictionaries

7 pointsby ankit_it09about 2 years ago

3 comments

marzipanWhaleabout 2 years ago
I really like Raymond Hettinger&#x27;s video on Python dictionaries: <a href="https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=npw4s1QTmPg">https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=npw4s1QTmPg</a>
评论 #35711815 未加载
eesmithabout 2 years ago
This is deeply wrong.<p>&gt; Python then calculates the hash value for each key in the dictionary using the MurmurHash3 hash function.<p>Umm... this isn&#x27;t right. At all. Depending on configuration, Python uses an external hash, a Modified Fowler-Noll-Vo (FNV) hash, or SipHash.<p>Here&#x27;s a quote from Include&#x2F;pyhash.h :<p>* The values for Py_HASH_* are hard-coded in the * configure script. * * - FNV and SIPHASH* are available on all platforms and architectures. * - With EXTERNAL embedders can provide an alternative implementation with::<p>and the implementations are in Python&#x2F;pyhash.c .<p>The only &quot;murmur&quot; in the repo is in Tools&#x2F;peg_generator&#x2F;data&#x2F;top-pypi-packages-365-days.json as a mention of a PyPI modules.<p>And the linked-to Wikipedia page at <a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;MurmurHash" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;MurmurHash</a> says: &quot;The authors of the attack recommend to use their own SipHash instead&quot; to avoid collision attacks.<p>(Also, the example hash is 5478795832145536229 which is a 64-bit hash, while the Wikipedia page says MurmurHash3 generates a 32-bit or 128-bit hash value.)<p>&gt; When a hash collision occurs, Python stores multiple key-value pairs in the same bucket and uses a linked list to store them.<p>Umm ... that isn&#x27;t right either.<p>A linked list is an &quot;open hashing&quot;&#x2F;&quot;separate chaining&quot; hash table, but Python uses &quot;closed hashing&quot;&#x2F;&quot;open addressing.&quot; As the linked-to Python source explains, &quot;Open addressing is preferred over chaining since the link overhead for chaining would be substantial (100% with typical malloc overhead).&quot;<p>skilled&#x27;s comment about this being ChatGPT generated is flagged and dead, but ChatGPT seems good at being both wrong and confident. Just like this essay.
评论 #35712709 未加载
评论 #35714871 未加载
trishmapow2about 2 years ago
Note that dictionaries are officially ordered since Python 3.7.
评论 #35711812 未加载
评论 #35711684 未加载