From this list:
N = [1,2,2,3,3,3,4,4,4,4,5,5,5,5,5]
I\'m trying to create:
L = [[1],[2,2],[3,3,3],[4,4,4,4],[5,5,5,5,5]]
You can do that using numpy too:
import numpy as np N = np.array([1,2,2,3,3,3,4,4,4,4,5,5,5,5,5]) counter = np.arange(1, np.alen(N)) L = np.split(N, counter[N[1:]!=N[:-1]])
The advantage of this method is when you have another list which is related to N and you want to split it in the same way.