title: Recursive function doesn't work despite empty stack test
body: <p>I don't know why the line <code>if len(stack)==0: return 0</code> doesn't work.</p>
  
  <p>Elements of the graph list represent nodes, for example: <code>[2, 6]</code> means that node with value 2 -> node with value 6, similarly node with value 4 is connected to nodes with value 7, 8, 9 (three descendant nodes).</p>
  
  <p>I wonder whether the route from <code>goal[0]</code> to <code>goal[1]</code> exists or not. </p>
  
  <p>In my example, there is no route.</p>
  
  <pre><code>graph_list=[[2, 6], [4, 7], [5, 7], [1, 5], [2, 9], [4, 9], [4, 8], [5, 3], [7, 8]]
  goal=[1, 9]
  
  stack=[goal[0],]
  
  def check_func(d_list, goal):
  
      if len(stack)==0:
          return 0
  
      for node in d_list:
          if node[0]==stack[-1]:
              stack.append(node[1])
              d_list.remove(node)
              check_func(d_list, goal)
  
      if stack[-1]==goal[1]:
          return 1
  
      else:
          stack.pop(-1)
          print(stack)
          check_func(d_list, goal)
  </code></pre>
  
  <p>After some iterations, at the following line, error occur. </p>
  
  <blockquote>
    <p>if stack[-1]==goal[1]:<br>
    IndexError: list index out of range</p>
  </blockquote>
  
  <p>I don't understand why this error occurs. I think the first line of the function code prevents the error.</p>