Skip to content

Instantly share code, notes, and snippets.

@binary-ibex
Created November 5, 2023 09:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save binary-ibex/f41c0b449956e62c436732b043d99b42 to your computer and use it in GitHub Desktop.
Save binary-ibex/f41c0b449956e62c436732b043d99b42 to your computer and use it in GitHub Desktop.
Reverse the string but keep the position of the spaces same as the original string
s = "I live in the India"
t = s[::-1].replace(" ", "")
s = list(s)
index= 0
for i in range(len(s)):
if s[i] != " ":
s[i] = t[index]
index += 1
print(''.join(s))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment