Guest User

Untitled

a guest
May 24th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. import location
  2. import os
  3.  
  4. #Given a string S, containing special characters and all the alphabets, reverse the string without affecting the positions of the special characters.
  5.  
  6. def flipString(theString):
  7.  
  8. holdThese = ""
  9. listChars = list(theString)
  10.  
  11. for char in listChars:
  12. if char.isalpha():
  13. holdThese = char + holdThese
  14.  
  15. print("Flipped order: ", holdThese)
  16. for idx, char in enumerate(listChars):
  17. if char.isalpha():
  18. listChars[idx] = holdThese[0]
  19. holdThese = holdThese[1:]
  20.  
  21. print(holdThese)
  22. print("".join(listChars))
  23.  
  24.  
  25. flipString("abc%sld*")
Add Comment
Please, Sign In to add comment