N
Newsfeeds
Hello All,
Could anyone tell me why this code produces the output it does?
noAdjacencies = 2
gridsPerAdj = 3
rows = 4
columns = 5
gridSystemId = [[None]*columns]*rows
for row in range(rows):
for column in range(columns):
gridSystemId[row][column] = "%d-%d" % (row,column)
print gridSystemId
Produces:
[['3-0', '3-1', '3-2', '3-3', '3-4'], ['3-0', '3-1', '3-2', '3-3', '3-4'],
['3-0
', '3-1', '3-2', '3-3', '3-4'], ['3-0', '3-1', '3-2', '3-3', '3-4']]
Rather than:
[['0-0', '0-1', '0-2', '0-3', '0-4'], ['1-0', '1-1', '1-2', '1-3', '1-4'],
['2-0
', '2-1', '2-2', '2-3', '2-4'], ['3-0', '3-1', '3-2', '3-3', '3-4']]
Thanks for your help,
Chris M.
Could anyone tell me why this code produces the output it does?
noAdjacencies = 2
gridsPerAdj = 3
rows = 4
columns = 5
gridSystemId = [[None]*columns]*rows
for row in range(rows):
for column in range(columns):
gridSystemId[row][column] = "%d-%d" % (row,column)
print gridSystemId
Produces:
[['3-0', '3-1', '3-2', '3-3', '3-4'], ['3-0', '3-1', '3-2', '3-3', '3-4'],
['3-0
', '3-1', '3-2', '3-3', '3-4'], ['3-0', '3-1', '3-2', '3-3', '3-4']]
Rather than:
[['0-0', '0-1', '0-2', '0-3', '0-4'], ['1-0', '1-1', '1-2', '1-3', '1-4'],
['2-0
', '2-1', '2-2', '2-3', '2-4'], ['3-0', '3-1', '3-2', '3-3', '3-4']]
Thanks for your help,
Chris M.