Help Reverse


Oops, try again. Does your reverse function take exactly one argument (a string)? Your code threw a "sequence item 0: expected string, int found" error.

def reverse(x):
    letter = []
    for char in range(len(x)-1, 0-1, -1):
    return "".join(letter)

Help i'm not even sure what the range(len(x)-1, 0-1, -1) is completely for . How does this reverse the order of the string entered for x? Also, isn't range only supposed to take two values?




char is just an integer, but this integer do happen to match the indexes of letter.

range will give you the indexes needed (from high to low) to reverse the string

range can have 3 values:

range(start, stop, step)

you start on the right side (len(x) -1), the stop value is -1 because range doesn't include its stop value and strings are zero indexed based. Given you are going from high to low value, you need to specify negative steps/strides


What lesson was the three range values taught because I do not remember that at all. I mean it makes perfect sense now that it has been explained but I wish it would've been covered in the first place.


Hello Stetim94,

For the stop value, why cannot we use '-1' directly instead of saying '0-1'?


who says we can't?


:grinning: Okay thanks!


Hello Stetim94,

Also how does " ".join(letter) convert a list to a string? Is the join function a sequence of appends to an empty string?


someone build a function (join) to make it easier to get from list to string. Its the purpose of the function


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.