Reversing string characters while keeping them in the same position
Guess you want:
string = 'This is the string'
def Reverse(string):
return ' '.join([s[::-1] for s in string.split(' ')])
print(Reverse(string))
Gives:
sihT si eht gnirts
~
def Reverse(string):
length = len(string)
emp = ""
for i in range(length-1,-1,-1):
emp += string[i]
return emp
myString = 'This is the string'
print ' '.join([Reverse(word) for word in myString.split(' ')])
OUTPUT
sihT si eht gnirts