I am trying to manually (without the built in function) reverse a string of text, however the code gives me a "list assignment index out of range" for list_rev[u] = list_[i]
. I don't understand why that happens? What I am trying to do is take the text from the list_
and place it in list_rev
in a reverse order and then print list_rev
.
Thanks!
text = raw_input("Word?")
text = str(text)
def reverse(text):
list_rev = []
list_ = []
length = int(len(text))
k = 0
while k < (length):
list_.append(str(text)[k])
k += 1
i = int(length-1)
u = 0
while i >= 0:
list_rev[u] = list_[i]
u += 1
i -= 1
return list_rev,
print reverse(text)