0

How can I index this 3D array in Python? Why this output?

#declaration of 3d array a=[[[0]*3]*3]*3 https://code.sololearn.com/c6G38kyWflP4/?ref=app

29th Jan 2022, 5:15 AM
David Ortega
David Ortega - avatar
3 Respuestas
+ 5
print(a[0][1][2]) returns 6th 0 from the left.
29th Jan 2022, 6:07 AM
Simba
Simba - avatar
+ 4
That's a problem of python not Sololearn. You can try this instead a = [[[0]*3 for i in range(3)] for j in range(3)] a[0][1][2]=1 print(a) https://stackoverflow.com/questions/240178/list-of-lists-changes-reflected-across-sublists-unexpectedly
29th Jan 2022, 7:49 AM
Simba
Simba - avatar
0
I think there is a problem in this app. If I try: a[0][1][2]=1 print(a) The output is not right
29th Jan 2022, 6:53 AM
David Ortega
David Ortega - avatar