I have a list
arr=[1,-1,4,-1,4,2]
Is there a way to convert it to [[1],[4],[4,2]]?
Basically the -1 indicates where a sub-list ends
I tried
number_of_sublists=arr.count(-1)
lst=[[]]*(number_of_sublists+1)
idx=0
for i in arr:
print(idx)
if i==-1:
idx+=1
else:
lst[idx].append(i)
print(lst)
but it is giving me the output
[[1,4,4,2],[1,4,4,2],[1,4,4,2]]
Why is this happening