Message159899
N = 5
board_1 = [[0 for _ in range(N)] for __ in range(N)]
is not the same as:
board_2= [[0]*N]*N
One makes a proper list of lists (the first), the second makes a new kind of animal were board_2[1][1] = 99 changes a whole column.
Oddly, testing board_1 == board_2 is True!
I'm teaching Python to non-majors, and this is a tough one to explain. |
|
Date |
User |
Action |
Args |
2012-05-04 04:13:42 | darrell | set | recipients:
+ darrell |
2012-05-04 04:13:42 | darrell | set | messageid: <1336104822.52.0.958479666589.issue14719@psf.upfronthosting.co.za> |
2012-05-04 04:13:41 | darrell | link | issue14719 messages |
2012-05-04 04:13:41 | darrell | create | |
|