You can use zip to form subsets and check if your sequence is present in those.
Here is a generalized way to do it:
L = [0,1,2,3,4,5,6,7,8,9]
S = [1,2,3]
if tuple(S) in zip(*(L[i:] for i in range(len(S)))):
print("found")
else:
print("not found")
Using parameter unpacking *(...
gives zip as many sub-lists as there are elements in S
. Each of these sublist starts at a different offset so zip will receive L[0:],L[1:],L[2:],... which will form tuples with every sublist of length len(S)
.
If you don't want to use zip(), you can use indexes to form the subsets:
if S in (L[i:i+len(S)] for i in range(len(L))):
print("found")
else:
print("not found")
The string strategy requires that the separator avoids overstepping boundaries (e.g. not finding "1,2,3" in "11,2,31"). This can be achieved by using "][" as the separator so that all values are enclosed in the same way ("[1][2][3]" in "[11][2][31]"):
if str(S).replace(", ","][") in str(L).replace(", ","]["):
print("found")
else:
print("not found")
While this works on numeric values, it can still fail if the values are strings (which may contain any pattern including the string version of the sequence).