title: Searching for key string within target string in Python recursively
body: <p><em>The following is for Python 3.2.3.</em></p>
  
  <hr>
  
  <p>I would like to write a function that takes two arguments, a key string and a target string.  These function is to <strong>recursively</strong> determine (it must be recursive) the positions of the key string in the target string.</p>
  
  <p>Currently, my code is as follows.</p>
  
  <pre><code>def posSubStringMatchRecursive(target,key):
      import string
      index=str.rfind(target, key)
      if index !=-1:
          print (index)
          target=target[:(index+len(key)-1)]
          posSubStringMatchRecursive(target,key)
  </code></pre>
  
  <p>The issue with this is that there is no way to store all the locations of the key string in the target string in a list as the numbers indicating the location will just be printed out. </p>
  
  <p>So, my question is, <em>is there any way to change the code such that the positions of the key string in the target string can be stored in a list</em>?</p>
  
  <hr>
  
  <h2>Example Output</h2>
  
  <pre><code>countSubStringMatchRecursive ('aatcgdaaaggraaa', 'aa')
  
  13
  12
  7
  6
  0
  </code></pre>
  
  <hr>
  
  <h2>Edit</h2>
  
  <p>The following code seems to work without the issue in Ashwini's code. Thanks, Lev.</p>
  
  <pre><code>def posSubStringMatchRecursive(target,key):
      import string
      index=str.rfind(target, key)
      if index ==-1:
          return []
      else:
          target=target[:(index+len(key)-1)]
          return ([index] + posSubStringMatchRecursive(target,key))
  </code></pre>