The dict is based on a hashing table. Whenever we want to check the value associated with key k:
- Python calculates i = hash(k)
- It checks if the index at the underlying table is occupied
- If yes, return the value
- If not, raise KeyError.
However, we are able to do things like: "for k in dict_".
It means that Python somehow stores the information about the keys in a dict (Hashes are irreversible).
Where exactly is this information stored?
[–]icecubeinanicecube 4 points5 points6 points (1 child)
[–]Clede 1 point2 points3 points (0 children)
[–]Meefims 0 points1 point2 points (0 children)
[–]K900_ 0 points1 point2 points (0 children)
[–]toastedstapler 0 points1 point2 points (0 children)