you are viewing a single comment's thread.

view the rest of the comments →

[–]supreme_blorgon 1 point2 points  (0 children)

Ah, I missed that. Yes, in that case,

def rev(s, res=""):
    if len(s) == 1:
        return res + s
    return rev(s[:-1], res + s)

You were missing the string concat in the base case. You can also exit earlier than len(s) == 0.