Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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*")
Add Comment
Please, Sign In to add comment