Skip to content

Instantly share code, notes, and snippets.

@lopezm1
Created May 19, 2018 21:27
Show Gist options
  • Save lopezm1/b536a1a342e767008aa496dbb0481646 to your computer and use it in GitHub Desktop.
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.
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