Whats wrong in this one


#1



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


'str' object does not support item assignment


return the reverse


def reverse(text):
    text2=""
    for i in range(len(text)):
        text2[len(text)-i-1]=text[i]    
    return text2


#2

here:

text2[len(text)-i-1]=text[i]

strings are immutable, they don't support item assignment like you are trying. For this to work, text2 should be a list (lists are mutable and do support item assignment)


#3

so, how do i accomplish the same using a list?


#4

isn't it in my answer?

all you need to do is change text2 from string to list

if you need more help, post an updated version of your code


#5

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