7/15 "!noh"


#1

When I run this code it only returns "!hon" what happened to the first 3 letters?

def reverse(text):
    text = list(text)
    print text
    result = []
    for letter in text:
        last_letter = text.pop()
        result.append(last_letter)
    return ''.join(result)

#2

Do this for me and you might understand what you are doing.

PUT IN IDE

a_list = [1, 2, 3, 4, 5]
for index, item in enumerate(a_list):
    print(a_list.pop(index))

After you do this you should understand a little better what you are doing to your list as you are working on it. Remember loops only reference the item but if you work directly on the object you can change the behavior of your loop.

Questions?


#3

Thanks, didn't understand what you meant till I found this http://stackoverflow.com/questions/13939341/why-does-a-for-loop-with-pop-method-or-del-statement-not-iterate-over-all-list


#4

This might Help!

def reverse(text):
x = len(text)
n = ""
while x > 0:
n = n + text[x-1]
x = x - 1
return n