How do I convert a flat list to a list of lists based on value of the elements in python3?

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

Answer

Try this:

arr=[1,-1,4,-1,4,2]
newarr = [[]]
for i in arr:
    if i != -1:
        newarr[-1].append(i)
    else:
        newarr.append([])
print(newarr)

Output:

[[1], [4], [4, 2]]