title: python - using dictionary to define a graph and find paths
body: <p>I have defined a graph as the following:</p>
  
  <pre><code>adj_matrix = {'1': set('2'),
                '2': set('3'),
                '3': set(['4', '5']),
                '4': set(''),
                '5': set('6'),
                '6': set('7'),
                '7': set('8'),
                '8': set(['9', '14']),
                '9': set(['10', '11']),
                '10': set(''),
                '11': set(['12', '13']),
                '12': set(''),
                '13': set(''),
                '14': set('15'),
                '15': set('16'),
                '16': set('17'),
                '17': set(['18', '19']),
                '18': set(''),
                '19': set('')}
  </code></pre>
  
  <p>And I am using the following to find the path between different nodes:</p>
  
  <pre><code>def find_path(graph, start, end, path=[]):
          path = path + [start]
          if start == end:
              return path
          if start not in graph:
              return None
          for node in graph[start]:
              if node not in path:
                  newpath = find_path(graph, node, end, path)
                  if newpath: return newpath
          return None
  </code></pre>
  
  <p>The issue is the function only works for nodes <code>1</code> to <code>14</code>. Like when I call <code>p = find_path(adj_matrix, '3', '14')</code> it works like a charm and gives me <code>['3', '5', '6', '7', '8', '14']</code> as the answer, but when I try <code>p = find_path(adj_matrix, '3', '15')</code> for instance, it returns <code>None</code>. Any ideas what is going on and how I could fix this?</p>