Created
May 19, 2018 21:27
-
-
Save lopezm1/b536a1a342e767008aa496dbb0481646 to your computer and use it in GitHub Desktop.
Given a string S, containing special characters and all the alphabets, reverse the string without affecting the positions of the special characters.
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
import location | |
import os | |
#Given a string S, containing special characters and all the alphabets, reverse the string without affecting the positions of the special characters. | |
def flipString(theString): | |
holdThese = "" | |
listChars = list(theString) | |
for char in listChars: | |
if char.isalpha(): | |
holdThese = char + holdThese | |
print("Flipped order: ", holdThese) | |
for idx, char in enumerate(listChars): | |
if char.isalpha(): | |
listChars[idx] = holdThese[0] | |
holdThese = holdThese[1:] | |
print(holdThese) | |
print("".join(listChars)) | |
flipString("abc%sld*") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment