For the whole list, it should be as simple as
sorted(l) == list(range(min(l), max(l)+1))
This keeps the original list, but making a copy (and then sorting) can be expensive if your list is especially long.
, Python 2 , range list. 3.x , range, sorted(l) list
sorted(l) == range(min(l), max(l)+1))
, n , :
def check(n, l):
subs = [l[i:i+n] for i in range(len(l)) if len(l[i:i+n]) == n]
return any([(sorted(sub) in range(min(l), max(l)+1)) for sub in subs])