Use with caution!
Common programming wisdom tells us that mutable objects should not be hashable since mutating the object might change its hash. But sometimes you really just want to have a dict or set of mutable things that you promise won't have their hashes change while in use. In Python there is a devious trick to do just that. Its legitimate use cases are very niche, but in a pinch you can use the identity of an object as as proxy for hashing the object itself. Learn how in this intermediate level Python video!
― mCoding with James Murphy (https://mcoding.io)
Source code: https://github.com/mCodingLLC/VideosS...
Datamodel docs: https://docs.python.org/3/reference/d...
Identity function: https://docs.python.org/3/library/fun...
SUPPORT ME ⭐
---------------------------------------------------
Sign up on Patreon to get your donor role and early access to videos!
/ mcoding
Feeling generous but don't have a Patreon? Donate via PayPal! (No sign up needed.)
https://www.paypal.com/donate/?hosted...
Want to donate crypto? Check out the rest of my supported donations on my website!
https://mcoding.io/donate
Top patrons and donors: Jameson, Laura M, Dragos C, Vahnekie, Neel R, Matt R, Johan A, Casey G, Mark M, Mutual Information, Pi
BE ACTIVE IN MY COMMUNITY 😄
---------------------------------------------------
Discord: / discord
Github: https://github.com/mCodingLLC/
Reddit: / mcoding
Facebook: / james.mcoding
CHAPTERS
---------------------------------------------------
0:00 Intro - hashing
1:20 Alternatives
1:44 Object identity
2:15 FORBIDDEN - IdMapping
3:14 FORBIDDEN - IdSet
3:44 See it in action
4:00 The downside
5:07 Thanks