Hackbright Code Challenges

Reverse a String Recursively: Solution

Reverse a String Recursively: Solution

Problem

Reverse a String Recursively

Whiteboard

Medium

Challenge

Easier

Concepts

Recursion, Strings

Download

rev-string-recursively-solution.zip


reverse.py
def rev_string(astring):
    """Return reverse of string using recursion.

    You may NOT use the reversed() function!
    """

    # START SOLUTION

    if len(astring) < 2:
        return astring

    return astring[-1] + rev_string(astring[:-1])