python 2.7 string reverse
<p>If I need to implement string reverse by myself in Python 2.7 other than using system library, wondering if any more efficient solutions? I tried my code runs slow for a very long string (e.g. a few thousand characters). Thanks.</p>

<p>For string reverse I mean, for example, given s = "hello", return "olleh". </p>

<pre><code>def reverseString(self, s):
    """
    :type s: str
    :rtype: str
    """
    if not s:
        return ''
    temp = []
    result=''
    for i in range(len(s)-1,-1,-1):
        result += s[i]
    return result
</code></pre>

<p>regards,
Lin</p>

<p>Try recursion</p>

<pre><code>def reverse(str):
    if str == "":
        return str
    else:
        return reverse(str[1:]) + str[0]
</code></pre>

python python-2.7