title: Reading adjacent elements in graph in python
body: <p>I'm representing a graph in python in a list in this manner:</p>
  
  <pre><code>[[1, 2, 3], [4, 5, 6], [7, 8, 9]]
  </code></pre>
  
  <p>What I want now is all the adjacent elements of a particular node?</p>
  
  <p>For e.g</p>
  
  <pre><code>1 -&gt; 2, 4, 5
  5 -&gt; 1, 2, 3, 4, 6, 7, 8, 9
  </code></pre>
  
  <p>I understand the way to do would be combinations of i-1,i+1, j-1, j+1 with i and j as rows and columns. But seems natural to suit a C solution where you put boundary constraints in the for loops.</p>
  
  <p>Is there a pythonic way to do it without checking boundary constraints for all the 8 possible choices.</p>
  
  <p>There is no ordering that I need. The matrix here can be any m x n.</p>