How to save a hash table of lists in Python (hash by identifier)?

I need to save the set of list hashed by id : two lists are equal if they are the same object.

Not only does using tuple not make sense semantically , but I also need to mutate lists sometimes (add a few elements to the end every once in a while), so I can't use tuple .

How to save a hash set of lists hashed by id in Python?

+4
source share
1 answer

Use dict instead of set, and let the id list be the key:

 dct[id(lst)] = lst 

Check for a list in the "set" using id(lst) in dct .

+14
source

Source: https://habr.com/ru/post/1448029/


All Articles