I have a simple list like this:
mylist=[0,1,2,3,4,5,6,7,8,9]
which I want to slice creating a list of lists. The intended outcome is:
sliced=[[0],[0,1],[0,1,2],[0,1,2,3],...]
First attempt:
sliced=[mylist[i:i+n] for i in range(0, len(mylist), n)]
wrong result:
sliced=[[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]]
Second attempt:
sliced=[[mylist[l]] for l in range(0,10,1)]
wrong result:
sliced=[[0], [1], [2], [3], [4], [5], [6], [7], [8], [9]]
How should I handle this?