python / psf-infra-meta

Meta-repository for PSF backed or managed systems. Created mainly for the issue tracker :)
10 stars 9 forks source link

Abnormal alignment in initialization of two-dimensional list #110

Closed zlwq closed 3 years ago

zlwq commented 3 years ago

When creating a two-dimensional list like this,everything is OK.

bod=[[0]*6+[1]]+[[0]*6+[1]]+[[0]*7]+[[0]*7]+[[0]*7]+[[0]*7]+[[0]*3+[1]*4]
bod
Out[35]:
[[0, 0, 0, 0, 0, 0, 1],
[0, 0, 0, 0, 0, 0, 1],
[0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 1, 1, 1, 1]]
bod[4][5]=1
bod
Out[35]: 
[[0, 0, 0, 0, 0, 0, 1],
[0, 0, 0, 0, 0, 0, 1],
[0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 1, 0],
[0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 1, 1, 1, 1]]

Another compact style issues an error,check it out:

bod=[[0]*6+[1]]*2+[[0]*7]*4+[[0]*3+[1]*4]

bod[4][5]=1

bod
Out[41]: 
[[0, 0, 0, 0, 0, 0, 1],
 [0, 0, 0, 0, 0, 0, 1],
 [0, 0, 0, 0, 0, 1, 0],
 [0, 0, 0, 0, 0, 1, 0],
 [0, 0, 0, 0, 0, 1, 0],
 [0, 0, 0, 0, 0, 1, 0],
 [0, 0, 0, 1, 1, 1, 1]]'

or

bod=[[0]*6+[1]]*2+[[0]*7]*4+[[0]*3+[1]*4]

bod[0][0]=1

bod
Out[44]: 
[[1, 0, 0, 0, 0, 0, 1],
 [1, 0, 0, 0, 0, 0, 1],
 [0, 0, 0, 0, 0, 0, 0],
 [0, 0, 0, 0, 0, 0, 0],
 [0, 0, 0, 0, 0, 0, 0],
 [0, 0, 0, 0, 0, 0, 0],
 [0, 0, 0, 1, 1, 1, 1]]'

You may find the error patterns.

zlwq commented 3 years ago

In python 3.7.10 (default, Feb 26 2021, 13:06:18) [MSC v.1916 64 bit (AMD64)] with Spyder

matrixise commented 3 years ago

Unrelated to Python and the infrastructure of the PSF.