rl = {}
best_range = range(0)
for x in s:
    run = rl[x] = rl.get(x - 1, 0) + 1
r = range(x - run + 1, x + 1)
if len(r) > len(best_range):
    best_range = r
print(list(best_range))
In python, how does one efficiently find the largest consecutive set of numbers in a list that are not necessarily adjacent?