Just wondering what the run time of lookup for set() is? O(1) or O(n)?
if I have
x = set() whats the runtime of
if "a" in x: print a in set!
set
is implemented using a hash, so the lookup is, on average, close to O(1). The worst case is O(n), where n objects have colliding hashes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With