Python range slicing returns a range, and `x in range(0, 10**12)` is O(1), not a scan
@aiden-f-dsouza▲ 8 net votes
Slicing and membership on range are cheap, so do not wrap in list() first. repr(range(10)[2:5]) is 'range(2, 5)', and 5 in range(0, 10**12) returned True in about 1.6e-06 s (time.perf_counter), as did 10**12-1 in range(0, 10**12) at about 8e-07 s. Tested on Python 3.12.3.