Blog Archive

search

Tuesday, August 6, 2019

Python program where all occurrences of different char have been changed to '$' except first of that character

a = input('Enter a string ')
b = a
nc = ''
for n in a:
    c=0
    for m in b:
        if(m is n and c>0):
            nc = nc + '$'
        elif(m is n):
            c=c+1
            nc = nc + m
        else:
            nc = nc + m
    b = nc
    nc = ''
print(b)

No comments:

Post a Comment

Python program to create a string from two given strings concatenating uncommon characters of the said strings

PROGRAM :  a = input('Enter a string : ') b = input('Enter a string : ') c='' for i in a:     if(i not in b):...