我已經基本與此創建一個二維網格陣列:爲什麼此列表以錯誤的順序返回x和y?
def createRoom(self):
self.room = [[0] * 8 for x in xrange(8)]
for x in xrange(8):
self.room[x][0] = 2
for j in xrange(8):
self.room[0][j] = 2
for i in xrange(8):
self.room[-1][x] = 2
for n in xrange(8):
self.room[n][-1] = 2
for x in xrange(6):
self.room[1][x+1] = 1
for x in xrange(1):
self.room[2][x+6] = 1
for x in xrange(1):
self.room[3][x+6] = 2
for x in xrange(1):
self.room[4][x+6] = 2
for x in xrange(1):
self.room[3][x+5] = 1
for x in xrange(1):
self.room[4][x+5] = 1
for x in xrange(1):
self.room[5][x+6] = 1
for x in xrange(6):
self.room[6][x+1] = 1
for x in xrange(5):
self.room[x+1][1] = 1
return self.room
,並使用PrettyPrinter它看起來像這樣:
[ [2, 2, 2, 2, 2, 2, 2, 2],
[2, 1, 1, 1, 1, 1, 1, 2],
[2, 1, 0, 0, 0, 0, 1, 2],
[2, 1, 0, 0, 0, 1, 2, 2],
[2, 1, 0, 0, 0, 1, 2, 2],
[2, 1, 0, 0, 0, 0, 1, 2],
[2, 1, 1, 1, 1, 1, 1, 2],
[2, 2, 2, 2, 2, 2, 2, 2]]
,但是當我想self.room [6] [ 3]它返回1而不是2.
除非我將順序更改爲self.room [3] [6],爲什麼要這樣做?
只是複製該文字,而不是張貼圖像請。 – 2012-03-06 00:05:16