3 ms·
That value will not change when the contents of the dict are updated. You’re keying on the dict itself rather than the hashed contents. That’s what you want in
by goodside 7y ago
That value will not change when the contents of the dict are updated. You’re keying on the dict itself rather than the hashed contents. That’s what you want in some situations, but it’s not what the parent post is looking for.
- Nullabillity 7y agoIt's also not reliable, since the same address can be reused if the dict is GCed. This is actually really easy to induce in Python, since it uses immediate refcounting. In my REPL (3.7.3): >>> a = {} >>> x = id(a) >>> del a >>> a = {} >>> y = id(a) >>> x == y True