Recursive functions : Inversing word
<p>I'm trying to make a simple function that inverses a string using recursion.</p>

<p>this is what i tried : </p>

<pre><code>    def inverse(ch):
        if ch=='' :
            return ''
        else:
            return ch[len(ch)]+inverse(ch[1:len(ch)-1])

    print inverse('hello')
</code></pre>

<p>And this is what i get : </p>

<blockquote>
  <p>line 13, in inverse
      return ch[len(ch)]+inverse(ch[1:len(ch)-1]) IndexError: string index out of range</p>
</blockquote>

<p>Check this:</p>

<pre><code>ch[len(ch)-1]+inverse(ch[0:len(ch)-1]) 
</code></pre>

python recursion