Help with Reverse!


#1




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

Why won't the .join() work?

def reverse(text):
    output=[]
    for i in range(len(text)-1,-1,-1):
        output.append(text[i])
        ' '.join(output)
    return output


#2

It's working plenty, but what do you do with its result?
Also, how many times do you need to use join?


#3

I just realized that the .join() should either be assigned to a variable or returned; else it won't work quite as expected.
Plus yes, I should intend the statement in such a way it runs just once. :slight_smile:
return ''.join(output)
Thanks!


#4

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