title: How to use list to force IndexError?
body: <p>Suppose I have a matrix like list <code>map</code>, where I am storing some objects. Now as per as how list works, <code>map[x-1]</code> yields in <code>map[elemInList-1]</code>. Apart from manually setting boundaries of x like if <code>x &lt; 0</code>, is there any other workaround?</p>
  
  <p>This is what I was trying</p>
  
  <pre><code>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
  </code></pre>
  
  <p>Example:</p>
  
  <pre><code>a b c d e
  f g h i j
  k l m n o
  </code></pre>
  
  <p>What I'm trying to do is, map the neighboring elements from each position. So for each positions, I'm trying to add left, right, up and down positions.Now suppose I'm at <code>[1][0]</code>(F) and trying to check if anything exists for its left. [1][0 - 1] would point to j, which is not what I'm trying to accomplish.</p>