Reverse, need help!


though I reverse the arrangement of the word, it print out with extra codes.
the message shows that "It returns "['!', 'n', 'o', 'h', 't', 'y', 'P']" when it should return "!nohtyP"."
please help me out!

def reverse(text):
    for char in text:
        a.insert(0, char)
    return a 
    print ''.join(a)


What prints in the console?

Because of indentation this line will never be seen by the parser. It follows return.


because it is a list , you may consider using a string instead :
a=" " then get the length of text using len(text) , while the length is >0 a will take text[Text_length - 1] and Text_length will be decremented by 1

I tried your way :
def reverse(text):
for c in text:
l.insert(0, c)

return ''.join(l)


I did the same thing. Return the list already joined -
return ''.join(a)