title: Convert a 2D array to a dictionary Python
body: <p>I am trying to convert a 2d array with really specific property to a dictionary. The property is that the value inside a matrix, corresponds to possibility to move in direction (upwards, downwards, left, right).</p>
  
  <p>I have been trying to flatten it and then work on the new array, but indexing gets really nested. I have 2 questions: How to add keys and values to a dictionary? And may I ask if I am going on right direction?</p>
  
  <p>For now, I assume that I am doing something such as:</p>
  
  <pre class="lang-py prettyprint-override"><code># assuming the matrix to be:
  # [[2, 1, 1],
  #  [1, 2, 2],
  #  [2, 1, 2]]
  # so for instace if I am on coordinate on the upper row in the middle,
  # I can move 1 position to the left, one position to right, and one pos down.
  # I made this simple example to show what I am trying to do
  b = [[2, 1, 1], [1, 2, 2], [2, 1, 2]]
  a = make_flat_arr(b)
  print(a)
  position = [str((len(b))**2)] * (len(b))**2
  for j in range(len(b)**2):
      position[j] = 'Pos{' + str(j % len(b)) + '}{' + str(j // len(b)) + '}'
      print(position[j])
  
  for j in range(len(b)**2):
      # HOW TO APPEND A DICTIONARY KEY?
      if j - b[j] &gt; -1:
          # add a left move
          # HOW TO APPEND A PAIR KEY-VAL?  
      elif j + b[j] &lt; len(b):
  
      elif j -
  </code></pre>