7. reverse


#1

def reverse(text):
    x = []
        for i in range(len(text)-1,0,-1):
        print text[i]
        x.append(text[i])
        return x
    
print reverse("abcdef")

I'm not sure why this won't work
This is the output:
4
f
['f']


7. reverse
#2

a function ends the moment a return keyword is reached, so your function end in the first iteration of your loop, is this what you want?


#3

You should put more attention to indentation. In Python this is very important.


#4

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