title: Generating a Markov model from a matrix
body: <p>The definition may be wrong, so please correct me if that is so.. I need to generate a Markov model from a matrix of a following kind:</p>
  
  <pre><code>four    two "e"         
  four    two "e"         
  three   three   "e"         
  one three   "e"         
  zero    six one zero    "e" 
  two two "e"         
  two two "e"         
  two two "e"         
  two two "e"         
  two two "e"         
  four    zero    "e"         
  two two "e"         
  three   one three   "e"     
  three   "e"             
  four    one "e"         
  three   one "e"         
  two one one zero    two "e"
  two five    "e"         
  three   four    two "e"     
  zero    five    "e"         
  three   "e"             
  three   three   "e"         
  three   "e"             
  one one "e"         
  three   two "e"         
  one one "e"         
  three   two zero    zero    zero    "e"
  three   three   "e"         
  three   one "e"         
  three   two "e"         
  </code></pre>
  
  <p>I need the output to be something like: {"four":[{2:"two", 3:"one",2:"exit"},{...}],"three":[{...}]}</p>
  
  <p>The numbers above are basically how many times does the transition to a particular state happens.. </p>
  
  <p>I am using python for this.</p>
  
  <p>Answer to the usual question "what have you tried?": "I tried a couple for approaches but they did not quite deliver, so I hope one of the answers will help clarifying things a bit".</p>
  
  <p>Thanks a lot. </p>
  
  <p>EDIT, updated to show the full matrix.</p>