Re:The Set data structure saved me from a world of pain
by cgriswald on Sunday October 18, 2020 @04:33PM
(#24820919)
I've had numerous occasions where doing set() on a python list was demonstrably faster for very large n with an unknown distribution rather than iterating through and potentially exiting early. I've always just assumed set() is doing the equivalent thing, but in the underlying C rather than in python.
Re:The Set data structure saved me from a world of pain
by root993 on Tuesday October 20, 2020 @06:38AM
(#24835835)
Yup, this is exactly why I went a Set. The fact that it can't contain duplicates is super handy
Re:The Set data structure saved me from a world of pain
by abhishekjha on Sunday October 18, 2020 @04:25PM
(#24820854)
Yes. Any kind of membership question is very easy to answer with a set/dict data structure.
Other trivially answerable questions include “what’s in me but not in this other collection”, “what’s in both of us”, “what’s in exactly one of us”, ... etc.