Towards understanding dictionaries

前端 未结 2 503
一向
一向 2021-01-21 04:22

I am required to use multiple hashtables, so in c++, I would normally use an std::unordered_map. So far I can understand that I can use a dictionary in Python, so let\'s assume

2条回答
  •  鱼传尺愫
    2021-01-21 04:44

    A simple Python shell experiment to show that different dictionaries can use the same key:

    >>> my_dict_1 = {'foo':1}
    >>> my_dict_2 = {'foo':2}
    >>> my_dict_1,my_dict_2
    ({'foo': 1}, {'foo': 2})
    

    This is a good discussion of how it is implemented. The key point is that each dictionary is allocated its own portion of memory (which can of course grow as needed). The exact same hash function is used for both dictionaries, but is being used to probe different areas in memory.

提交回复
热议问题