+ 2

Why the output is false ❓

Why x[0][0]=1 and y[0][0] working different ❓ https://code.sololearn.com/c04t9RSj9uTS/?ref=app

10th Feb 2020, 3:10 AM
ClassHacker
ClassHacker - avatar
6 ответов
+ 1
no x=[[0,0,0]]*3 this is still x = [0,0,0] then x[0][0] = 1 x then became [1,0,0] now as x is multiplied it becomes 3 x arrays as [[1,0,0] [1,0,0] [1,0,0]] x[0][0] is behaving like x[0][0] and x[0][0] and x[0][0] or [[x[0][0],0,0]]*3
10th Feb 2020, 4:05 AM
BroFar
BroFar - avatar
+ 3
It is false because x=[[1,0,0],[1,0,0],[1,0,0]] y=[[1,0,0],[0,0,0],[0,0,0]] So x==y is false
10th Feb 2020, 3:15 AM
Pedro H.J
Pedro H.J - avatar
+ 2
ClassHacker as Pedro H.J pointed out here is your code as we go line by line: https://code.sololearn.com/cgZx130N6PuE/?ref=app
10th Feb 2020, 3:35 AM
BroFar
BroFar - avatar
+ 1
check out line 12 on my code print([[x[0][0],0,0]]*3)
10th Feb 2020, 4:15 AM
BroFar
BroFar - avatar
10th Feb 2020, 5:07 AM
Oma Falk
Oma Falk - avatar
0
but why x[0][0] is behaving like x[1][0] and x[2][0]
10th Feb 2020, 3:59 AM
ClassHacker
ClassHacker - avatar