inp = [1, 2, 3, 5, 7, 8, 9, 10, 11, 12, 14, 17, 20, 25,27,28,29,31]
The expected output: If the adjacent variable is in series, fill with a hyphen. If not, append the given number.
Expected Output = [1-3,5,7-12,14,17,20,25,27-29,31]
I have taken an adjacent number using the below code. But the requirements are not satisfied.
inp = [1, 2, 3, 5, 7, 8, 9, 10, 11, 12, 14, 17, 20, 25,27,28,29,31]
for x,y in zip(inp[::],inp[1::]):
print(x,y)