Hackbright Code Challenges

Reverse a String

Reverse a String

Whiteboard

Easier

Concepts

Loops, Strings

Download

rev-string.zip

Solution

Reverse a String: Solution


Given a string, return the same string, reversed.

For example, as “porcupine” would reverse to “enipucrop”:

>>> rev_string("porcupine")
'enipucrop'

Don’t Use Built-In Functions

You may not use the Python built-in functions reverse or reversed to solve this. What other ways could you come up with?

We’ve provided a file, revstring.py, with a stub implementation of the function rev_string:

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

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