I'm confused about how to create a python3 two-dimensional array list.
a=[0]*3 for i in range(4)]
b = [[0]*3]*4
for i in range (4):
for jin range(3):
a[i][j]=f'{i}_{j}'
b[i][j]=f'{i}_{j}'
Due to the difference in the way two-dimensional array is created, the results will be different as follows:
For list inclusion of a,
[['0_0', '0_1', '0_2',] ,
['1_0', '1_1', '1_2'],
['2_0', '2_1', '2_2'],
['3_0', '3_1', '3_2']]
Multiply the list of b by
[['3_0', '3_1', '3_2',] ,
['3_0', '3_1', '3_2'],
['3_0', '3_1', '3_2'],
['3_0', '3_1', '3_2']]
How do I understand the difference in output?
python python3
a is another list and b is the same (as metropolis, payaneco wrote in the comments).
The figure below shows for easy visibility.
589 GDB gets version error when attempting to debug with the Presense SDK (IDE)
853 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
562 Who developed the "avformat-59.dll" that comes with FFmpeg?
563 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
© 2024 OneMinuteCode. All rights reserved.