def reverse(x): charcount = 0 xlist =  #xlist = x.split() for char in str(x): charcount += 1 chars = range(charcount) for i in range(charcount): xlist.append(str(x[i:(i + 1)])) # now I have a list consisting of the characters of the input str given to x reverselist =  subtractor = 1 for char in xlist: if xlist.index(char) == 0: reverselist.append(xlist[charcount - 1]) else: reverselist.append(xlist[(charcount - subtractor)]) subtractor += 1 reverse_string = '' for i in reverselist: reverse_string = (reverse_string + i) return reverse_string
index() always finds the first match. for example:
"letter".index("e") will always give
Thank you. You're a time saver.
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.