Optimizing Python Dictionary Lookup Speeds by Shortening Key Size?

前端 未结 2 486
别跟我提以往
别跟我提以往 2021-01-18 07:58

I\'m not clear on what goes on behind the scenes of a dictionary lookup. Does key size factor into the speed of lookup for that key?

Current dictionary keys are bet

2条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-18 08:25

    Python dictionaries are implemented as hash-maps in the background. The key length might have some impact on the performance if, for example, the hash-functions complexity depends on the key-length. But in general the performance impacts will be definitely negligable.

    So I'd say there is little to no benefit for the added complexity.

提交回复
热议问题