title: Saving recursive function results as array in Python
body: <p>I'm looking into recursive functions (not from libraries) for creating permutations with repetitions and I found some code that I feel like I understand. I'd like to take it a step further and try saving it as a Numpy array, but I can't seem to figure out where to "return" in order to save the permutations into an array. Please advise.</p>
  
  <pre><code>def _permutation_repeat(text, prefix, n, k):
      if k == 0: 
          print(prefix)
          return
  
      for i in range(n):
          new_prefix = prefix + text[i] 
          _permutation_repeat(text, new_prefix, n, k-1)
  
  
  def permutation_repeat(text, k):
      _permutation_repeat(text, "", len(text), k)
  
  
  permutation_repeat("ABCD", 2)
  </code></pre>
  
  <p>Code from: <a href="https://code.luasoftware.com/tutorials/coding-interview/permutations-with-repeating-characters/" rel="nofollow noreferrer">https://code.luasoftware.com/tutorials/coding-interview/permutations-with-repeating-characters/</a></p>