【发布时间】:2012-01-05 20:26:37
【问题描述】:
我正在使用 for 循环遍历二维列表:
def itr(lpic, lH, lW, x, y):
'''lpic=2D-Array; lH=Row_count; lW=Column_count;'''
stack = []
range_x = range(x-1, x+2)
range_y = range(y-1, y+2)
append = stack.append
for i in range_x:
if 0<=i<lH:#i is a valid index *Updated
for j in range_y:
if (0<=j<lW) and (lpic[i][j]=="0"):
lpic[i][j] = "1"
append([i, j])
return stack
我想知道是否有更好的方法来用 Python2.5 做同样的事情。
【问题讨论】:
标签: python loops multidimensional-array