Below was a program to create a transpose of the matrix. But due to some reason, it gives wrong input.
def transpose(arr):
new_arr = [[0]*len(arr)]*len(arr[0])
for i in range(len(arr)):
for j in range(len(arr[0])):
new_arr[j][i] = arr[i][j]
return new_arr
arr = transpose([[1,2,3],[4,5,6]])
print(arr)
Current Output: [[3, 6], [3, 6], [3, 6]]
Expected Output: [[1, 4], [2, 5], [3, 6]]
I couldn't really figure out what went wrong with this code?