3 Comments
Apr 9Liked by Avi Chawla

btw, lists aren't hashable because they're mutable. from so:

When you store the hash of a value in, for example, a dict, if the object changes, the stored hash value won't find out, so it will remain the same. The next time you look up the object, the dictionary will try to look it up by the old hash value, which is not relevant anymore.

To prevent that, python does not allow you to has mutable items.

Expand full comment
author

yes, totally, Spencer. Thanks for highlighting this :)

Expand full comment

Nice trick! Python needs immutable and hashable keys to guarantee that lookups are consistent and fast.

Expand full comment