Hacker News new | ask | show | jobs
by paskozdilar 1458 days ago
You can do that too, using the bisect, provided you have the __len__ and __getitem__ implemented:

    class C:
        def __len__(self): ...
        def __getitem__(self, i): ...
        def __contains__(self, x):
            i = bisect.bisect_left(self, x)
            return i < len(self) and self[i] == x
At that point it's just syntactic sugar.