This question already has an answer here:
- Pythonic way to convert a list of integers into a string of comma-separated ranges 7 answers
- group list of ints by continuous sequence 7 answers
I have a sequence of numbers in a list and I'm looking for an elegant solution, preferably list comprehension, to get the individual sequences (including single values). I have solved this small problem but it is not very pythonic.
The following list defines an input sequence:
input = [1, 2, 3, 4, 8, 10, 11, 12, 17]
The desired output should be:
output = [
[1, 2, 3, 4],
[8],
[10, 11, 12],
[17],
]