Problem in "reverse" exercise


#1

def reverse(text):
    rev=[]
    P=str(text)
    for x in range(len(P)):
        P[x]=rev[len(P)-x]
        
    return rev

it gives a "list index out of range" error.

Also what is the difference between "list index out of range" and "list assignment index out of range" error


#2

uhm.. this line:

rev[len(P)-x]

rev is an empty list? i think you want to get the value from P. also, len() start counting at 1, strings/list are zero indexed based, so you might want to do -1

a list index out of range is when you try to access a list with a index which is out of range, list assignement is when you try to append a item to a list to a position which is out of range


#3

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