3 ms·
Sets are my #1 favourite Python built-in. I used to have these tedious imperative functions for doing change detection on collections. Then I learned sets and i
by Waterluvian 8y ago
Sets are my #1 favourite Python built-in. I used to have these tedious imperative functions for doing change detection on collections. Then I learned sets and it turned into obvious code like:
added = b - a
removed = a - b
repeated = a & b
Etc.
Of course this is set theory and not Python specific. But still. Learn sets!
- joatmon-snoo 8y agofrozenset is a really nice one for enforcing immutabolity :)
- ForHackernews 8y agoFrozensets can also be keys in a dictionary.
- ehsankia 8y agoPycon 2019 about how to use Sets more in your every day code: https://www.youtube.com/watch?v=tGAngdU_8D8 https://www.youtube.com/watch?v=tGAngdU_8D8