Closed zlwq closed 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.
In python 3.7.10 (default, Feb 26 2021, 13:06:18) [MSC v.1916 64 bit (AMD64)] with Spyder
Unrelated to Python and the infrastructure of the PSF.
When creating a two-dimensional list like this,everything is OK.
Another compact style issues an error,check it out:
or
You may find the error patterns.