I use input [0,2,3,4,6,7,8,16,17,18,21,23,24,26,34,35,36,37,38,40,41,46,47]
But output [0,2,6,16,21,23,26,34,40,46] which is wrong Should be [2,6,16,23,34,40,46]
How to find the first number of multiple consecutive sequence in list?
If it is possible, can be editable to find the last one too Such that [4, 8, 18, 24, 38, 41, 47]
def find_consecutive_numbers(lst):
result = []
i = 0
while i < len(lst)-2:
if lst[i]+1 == lst[i+1] and lst[i+1]+1 == lst[i+2]:
result.append(lst[i])
i += 2
else:
i += 1
return result
I had tried to ask chatgpt, but result is not perfect. It use string to do first. But some unexpected numbers in list too