Practice Makes Perfect : Reverse


Oops, try again. Your function fails on reverse("coolstory"). It returns "yroootslc" when it should return "yrotslooc".

I am lost, could someone walk me through what is happening from the beginning of the while?

def reverse(x):
    for letter in x:
    while len(y)>=1:
        print y
    return "".join(z)
print reverse("coolstory")


remove() doesn't remove based index, for this we have del

remove() will remove the first match it can find, so if we would do:

['c', 'o', 'o', 'l', 's', 't', 'o', 'r', 'y'].remove('o')

we get:

['c', 'o', 'l', 's', 't', 'o', 'r', 'y']

so its impossible to remove the o in story first using remove()


Awesome thanks for your help!


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