I have a list in python [1, 2, 3, 4, 5, 6]. I want to generate all possible combinations of length 2, 3, 4 and 5. I have used itertools.combinations to generate the combinations but it doesn't generate continuous combinations only. For example, length 2 combinations should be only [1, 2], [2, 3], [3, 4], [4, 5], [5, 6]. Is there any faster way to generate than the following code?
for start, end in combinations(range(len(lst)), 2):
if end - start <= 4 and end-start >= 1:
print(lst[start:end+1])