I have a list:
a = [2, 3, 5, 6, 6, 7, 10, 11, 13, 14, 15, 16, 16, 17, 18, 20, 21]
Is it possible to make a function that shows the longest list of distinct, consecutive elements?
Please, show how to do it
In this case the answer should be:
13, 14, 15, 16, 17, 18
There is probably a more pythonic way, but I can't think of it right now, so here a very basic solution:
Assuming your list is sorted:
ETA: fixed last step;
The simplest thing to do seems to be to loop through the list once, building any sequences you can find and then print the longest one.