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


#1



https://www.codecademy.com/en/courses/python-intermediate-en-rCQKw/1/1?curriculum_id=4f89dab3d788890003000096#


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:
        list1.append(text[char_pos])
        char_pos -= 1
    return str(list1)
    print ''.join(str(list1))
    
print reverse('Hello')


#2

Fixed.

I changed

print ''.join(str(list1))

to

print str(''.join(list1))


#3

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.


#4

So now I have this -

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

What else is wrong with it?


#6

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


#7

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