HELP APPRECIATED - 7. Reverse - I can't figure out what the problem is


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

I can't figure out why it stays in list format when I have the .join() function

def reverse(text):
    list1 = []
    char_pos = len(text) - 1
    for char in text:
        char_pos -= 1
    return str(list1)
    print ''.join(str(list1))
print reverse('Hello')



I changed

print ''.join(str(list1))


print str(''.join(list1))


What is the point of str()? The quotes in the join expression should be evidence enough that the object is a string..

On the whole, this function is a mess and needs to be refactored and thought out again. If you need, we can point out the areas of concern.


So now I have this -

def reverse(text):
text_list = []
start_point = len(text) - 1
for char in text:
start_point -= 1
return ''.join(text_list)

What else is wrong with it?


Did you solve this or do we need to further examine it?


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