I am writing a simple program to replace duplicate characters in a string with *(asterisk)
. But here I can print the first occurrence of a repeating character in a string, but not other occurrences.
For example, if my input Google
, my output should be Go**le
.
I can replace characters that repeat with an asterisk, but just can't find a way to print the first occurrence of the character. In other words, my conclusion is now ****le
.
Take a look at my code for this: Python3
s = 'Google'
s = s.lower()
for i in s:
if s.count(i)>1:
s = s.replace(i,'*')
print(s)
Can someone tell me what needs to be done to get the desired result?