Pythonic way of expressing the simple problem:
Tell if the list
needleis sublist ofhaystack
#!/usr/bin/env python3
def sublist (haystack, needle):
def start ():
i = iter(needle)
return next(i), i
try:
n0, i = start()
for h in haystack:
if h == n0:
n0 = next(i)
else:
n0, i = start()
except StopIteration:
return True
return False