def _calculate_to_transitions(trans_probs):
 transitions = dict()
 for (from_state, to_state) in trans_probs:
  try:
   transitions[to_state].append(from_state)
  except KeyError:
   transitions[to_state] = [from_state]
 return transitions

def _calculate_to_transitions ( trans_probs ) : transitions = dict ( ) for ( from_state , to_state ) in trans_probs : try : transitions [ to_state ] . append ( from_state ) except KeyError : transitions [ to_state ] = [ from_state ] return transitions
calculate which to transitions are allowed for each state this looks through all of the trans_probs .