filmov
tv
A forbidden Python technique to put ANYTHING in a dict or set.
Показать описание
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!
SUPPORT ME ⭐
---------------------------------------------------
Sign up on Patreon to get your donor role and early access to videos!
Feeling generous but don't have a Patreon? Donate via PayPal! (No sign up needed.)
Want to donate crypto? Check out the rest of my supported donations on my website!
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 😄
---------------------------------------------------
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
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!
SUPPORT ME ⭐
---------------------------------------------------
Sign up on Patreon to get your donor role and early access to videos!
Feeling generous but don't have a Patreon? Donate via PayPal! (No sign up needed.)
Want to donate crypto? Check out the rest of my supported donations on my website!
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 😄
---------------------------------------------------
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
Комментарии