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
Today I was asked this same exercise on pen&paper, so I come up with this function for lists:
def rev(s): l = len(s) for i,j in zip(range(l-1, 0, -1), range(l//2)): s[i], s[j] = s[j], s[i] return s
which can be used with strings with "".join(rev(list("hello")))
"".join(rev(list("hello")))