How do Python dictionary hash lookups work?

前端 未结 5 2327
轮回少年
轮回少年 2020-12-13 14:42

How do Python dictionary lookup algorithms work internally?

mydi[\'foo\'] 

If the dictionary has 1,000,000 terms, is a tree search execut

5条回答
  •  孤街浪徒
    2020-12-13 15:10

    As you mentioned in your title, dicts are hash tables. No tree searching is used. Looking up a key is a nearly constant time operation, regardless of the size of the dict.

    You might find the answers to this question helpful: How are Python's Built In Dictionaries Implemented

提交回复
热议问题