Message331955
It seems that the definition of a matrix like this:
a=[[0,0]]*4
does not create the matrix correctly by create 4 times the same pointer.
After the matrix creation, a
print(a)
gives the following result:
[[0, 0], [0, 0], [0, 0], [0, 0]]
which looks normal
print(type(a)) and print(type(a[1]) give also the correct result:
list
But when we try to change a matrix element:
a[2][0]=1
print(a)
gives a false result:
[[1, 0], [1, 0], [1, 0], [1, 0]]
When the matrix definition is done like this:
a=[[0, 0], [0, 0], [0, 0], [0, 0]]
the behavior is "as expected"
a[2][0]=1
print(a)
gives the correct result:
[[0, 0], [0, 0], [1, 0], [0, 0]] |
|
Date |
User |
Action |
Args |
2018-12-17 09:04:28 | xda@abalgo.com | set | recipients:
+ xda@abalgo.com |
2018-12-17 09:04:28 | xda@abalgo.com | set | messageid: <1545037468.26.0.788709270274.issue35515@psf.upfronthosting.co.za> |
2018-12-17 09:04:28 | xda@abalgo.com | link | issue35515 messages |
2018-12-17 09:04:27 | xda@abalgo.com | create | |
|