Set


Here’s a question: how can you do membership look-up in O(1) time in Python?

One way is via a dictionary. But what if you don’t have values to store with the keys?

Then, you don’t really need that extra stuff. In that case, let’s use a set!

A Python set is like a mix between a list and dictionary: it only supports the ‘keys’, like a list, while still allowing membership checking in O(1) amortized, like a dictionary.