I want to create a multi dimensional Array out of normal array. When there is a 0 in my start array i want to change the row number by 1.
My start array looks like this:
arr = [1, 2, 3, 0, 4, 5, 6, 0, 7, 8, 9]
My futre multi array should look like this:
multi_arr = [[1, 2, 3],
[4, 5, 6],
[7, 8, 9]]
My code looks like this so far:
multi_arr = []
end = len(arr)
i = 0 #row
j = 0 #column
for h in range(end):
if arr[h] != 0:
j += 1
multi_arr[i][j]= arr[h]
elif arr[i] != 0:
i += 1
I always get a list index error with this code.