2 ms·
> But in general a “dict”, or if you really need an array, binary search, should be used. Where’s the one liner for that in python? For dict/set hash lookup, O
by dragonwriter 4y ago
> But in general a “dict”, or if you really need an array, binary search, should be used. Where’s the one liner for that in python?
For dict/set hash lookup, O(1):
x in s
For binary search on a sorted python list, it takes a standard library import (bisect), and the containment test is:
(i:=bisect.bisect_left(a, x)) < len(a) and a[i] == x