Question about nested lists!
rainlet
orrego at mail2000.com.tw
Thu Aug 2 22:59:06 EDT 2001
I use a nested list to make a 2-d array. The code follows:
floor_member = [ 0 ]
for x in range ( 9 ) :
floor_member.append ( 0 )
floor = [ floor_member ]
for y in range ( 9 ) :
floor.append ( floor_member )
floor [ 5 ] [ 5 ] = 1
for n in range ( 10 ) :
print floor [ n ]
#code end
I only assign floor [ 5 ] [ 5 ] = 1, but the result is :
[0, 0, 0, 0, 0, 1, 0, 0, 0, 0]
[0, 0, 0, 0, 0, 1, 0, 0, 0, 0]
[0, 0, 0, 0, 0, 1, 0, 0, 0, 0]
[0, 0, 0, 0, 0, 1, 0, 0, 0, 0]
[0, 0, 0, 0, 0, 1, 0, 0, 0, 0]
[0, 0, 0, 0, 0, 1, 0, 0, 0, 0]
[0, 0, 0, 0, 0, 1, 0, 0, 0, 0]
[0, 0, 0, 0, 0, 1, 0, 0, 0, 0]
[0, 0, 0, 0, 0, 1, 0, 0, 0, 0]
[0, 0, 0, 0, 0, 1, 0, 0, 0, 0]
Is this a bug? Please help me debug. I can't see anything wrong!
Thank you!
More information about the Python-list
mailing list