title: Python: Efficiently iterating over a multidimensional list
body: <p>I'm using for-loops to iterate over two-dimensional list:</p>
  
  <pre><code>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&lt;=i&lt;lH:#i is a valid index *Updated
                      for j in range_y:
                          if (0&lt;=j&lt;lW) and (lpic[i][j]=="0"):
                              lpic[i][j] = "1"
                              append([i, j])
      return stack
  </code></pre>
  
  <p>I'd like to know if there is a better way to do the same with Python2.5.</p>