title: Python yield statement issue in recursive function?
body: <p>Now, I learn to how to use <code>yield</code> in python program. so I want to implement <code>word permutation</code> in python.</p>
  
  <pre><code>def permuteArr(arr, index=0):
      '''(list, int) -&gt; list
  
      Get all the permutation of the elements in list.
      &gt;&gt;&gt; arr = ['a', 'b', 'c']
      &gt;&gt;&gt; for val in permuteArr(arr):
              print val
      '''
      if index == len(arr):
          yield arr
      else:
          for idx in range(index, len(arr)):
              arr[idx], arr[index] = arr[index], arr[idx]
              for val in permuteArr(arr, idx+1):
                  yield val
              arr[idx], arr[index] = arr[index], arr[idx]
  
  if '__name__' == '__main__':
      arr = ['a', 'b', 'c']
      for val in permuteArr(arr, 0):
          print val
  </code></pre>
  
  <p>However, I run it in python shell under window, the results are not correct. There are only four results.</p>
  
  <pre><code>&gt;&gt;&gt; for v in permuteArr(['a', 'b', 'c']):
      print v
  
  ['a', 'b', 'c']
  ['a', 'c', 'b']
  ['b', 'a', 'c']
  ['c', 'b', 'a']
  </code></pre>
  
  <p>Is anything wrong when I use yield or in my program?</p>