sorry if the answer could be easy, but i really can't understand why this is giving me so much problems...
I want to populate a matrix with elements of another list, but when i do Matrix[0][1] = 1 it modifies the second colums of EVERY row, instead of just the first row. I had never happened this problem before, i don't really understand.
This is the code:
NumAlberi = int(input())
AltezAlb = ["a"] * NumAlberi
NumVele = ["b"] * NumAlberi
valori = [[0] * NumAlberi] * NumAlberi
for c in range(NumAlberi):
AltezAlb[c], NumVele[c] = map(int, input().split())
ListaOrdinata = [[0] * 2] * NumAlberi
a = list(AltezAlb)
b = list(NumVele)
c = 0
print(ListaOrdinata)
while c < NumAlberi:
if c % 2 == 0:
tmp = max(a)
ListaOrdinata[c][0] = tmp
a.remove(tmp)
else:
tmp = min(a)
ListaOrdinata[c][0] = tmp
a.remove(tmp)
ListaOrdinata[0][1] = 1
c += 1
print(ListaOrdinata, a)
print(ListaOrdinata)```
This is the output:
[[0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0]]
[[5, 1], [5, 1], [5, 1], [5, 1], [5, 1], [5, 1]] [3, 4, 2, 4, 3]
[[2, 1], [2, 1], [2, 1], [2, 1], [2, 1], [2, 1]] [3, 4, 4, 3]
[[4, 1], [4, 1], [4, 1], [4, 1], [4, 1], [4, 1]] [3, 4, 3]
[[3, 1], [3, 1], [3, 1], [3, 1], [3, 1], [3, 1]] [4, 3]
[[4, 1], [4, 1], [4, 1], [4, 1], [4, 1], [4, 1]] [3]
[[3, 1], [3, 1], [3, 1], [3, 1], [3, 1], [3, 1]] []
[[3, 1], [3, 1], [3, 1], [3, 1], [3, 1], [3, 1]]
for example, at the end of everything, the last line of output should be:
[[5, 0], [2, 0], [4, 0], [3, 0], [4, 0], [3, 0]]
Thank you in advance