RenzCutie

StringOccur

Sep 28th, 2021 (edited)
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.31 KB | None | 0 0
  1. inStr = input("Enter a string: ")
  2. dic = {a:inStr.count(a) for a in inStr}
  3. dicRepeat = [a for a, b in dic.items() if b > 1]
  4.  
  5. tmpStr = inStr
  6. for i in range(len(dicRepeat)):
  7.     tmpLoc = tmpStr.index(str(dicRepeat[i]))
  8.     tmpStr = tmpStr[:tmpLoc + 1] + tmpStr[(tmpLoc + 1):].replace(dicRepeat[i],"$")
  9.  
  10. print(tmpStr)
Advertisement
Add Comment
Please, Sign In to add comment