title: Why does Itertool Permutations recurse till recursionError in def function?
body: <p>I'm just wondering why I'm getting the error: RecursionError: maximum recursion depth exceeded
  When trying:</p>
  <pre><code>
  def permutations(string):
      permlist = permutations(string)
      combolist = []
  
  
      for perm in list(permlist): 
          if ''.join(perm) not in combolist:
              combolist.append(''.join(perm))
  
      print(f&quot;{combolist}&quot;)
  </code></pre>
  <p>I get this error:</p>
  <pre><code>permlist = permutations(string)
    [Previous line repeated 996 more times]
  RecursionError: maximum recursion depth exceeded  
  </code></pre>
  <p>However, when I try it outside of a def, it works no problem:</p>
  <pre><code> 
  permlist = permutations('abba')
  combolist = []
   
   
  for perm in list(permlist): 
      if ''.join(perm) not in combolist:
          combolist.append(''.join(perm))
   
  print(f&quot;{combolist}&quot;)
   
  
  output:
  
  ['abba', 'abab', 'aabb', 'baba', 'baab', 'bbaa']
  </code></pre>
  <p>I'm not very familiar with itertools or permutations or anything, but I'm just wondering why the permutation is recurring in a def, is there any way to possibly run the permutation once in the def, when executing the for loop afterwards or something?</p>
  <p>Any help would be much appreciated!</p>