Created
November 5, 2023 09:45
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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