Reverse, need help!


#1

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):
    a=[]
    for char in text:
        a.insert(0, char)
    return a 
    print ''.join(a)

#2

What prints in the console?

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


#3

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):
l=[]
for c in text:
l.insert(0, c)

return ''.join(l)

#4

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