假设我有一个类似于listmap
的矩阵,在这里我存储了一些对象。现在根据列表的工作方式,map[x-1]
在map[elemInList-1]
中产生。除了像ifx < 0
那样手动设置x的边界之外,还有其他解决方法吗?你知道吗
这就是我想要的
for x in range(row):
for y in range(col):
try:
print "trying left", map[x][y - 1]
map[x][y].neighbors.append(map[x][y - 1])
except IndexError:
pass
示例:
a b c d e
f g h i j
k l m n o
我要做的是,从每个位置映射相邻的元素。所以对于每个位置,我都要加上左,右,上,下位置。现在假设我在[1][0]
(F)并试图检查它的左边是否存在任何东西。[1] [0-1]会指向j,这不是我想要实现的。你知道吗
这就是你想做的吗?你知道吗
相关问题 更多 >
编程相关推荐