Practice makes perfect- Reverse...Help!


Ok, so im turning the parameter of the function text into list. and i want to know how can i reverse the list and then change it back into a string?

Replace this line with your code. 
def reverse(text):
    text = [ ]
    for word in text:


That is actually wiping out the parameter. Use the list() function...

text = list(text)


def reverse(text):
    letter = []
    for word in list(text):

that's what i got.
error: Oops, try again. Your function fails on reverse("Python!"). It returns "['P', 'y', 't', 'h', 'o', 'n', '!']" when it should return "!nohtyP".

expected to happen:
letter was suppose to append every last word first. And after that i tried to turn [] into a string with str()...and error.


This could be named something like reverse_text, that says what it is.

Here would be where to use the variable name, letter.

for letter in list(text):
return ''.join(reverse_text)

That's the variable and return mechanics. Now we just have to figure out how to reverse it.


def reverse(text):
    reversed_text = []
    for word in list(text):
    return ''.join(reversed_text)

i have changed from append to insert because append can only take one argument. I don't know how my coded worked. But can you explained to me how reversed_text.insert(0,word) worked? Thank you for your time


Then you shouldn't use it as your solution. Write a solution that uses what you have learned in this module, up to this point. It can be done.


def reverse(text):
    reversed_text = []
    for word in list(text):
    return ''.join(reversed_text)

Ok, if im going to use append instead of insert.
how am i going to reverse it without using reverse()


That is the aim of this exercise, to come up with a method that does it manually, without the use of a built in function. We're learning how to implement a methodical step by step approach, not the fastest or easiest way.

You will not learn much if you don't think this one through.


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