I came across a strange Codecademy exercise that required a function that would take a string as input and return it in reverse order. The only problem was you could not use
This is my solution using the for i in range loop:
def reverse(string): tmp = "" for i in range(1,len(string)+1): tmp += string[len(string)-i] return tmp
It's pretty easy to understand. I start from 1 to avoid index out of bound.