Answers for "repeated char to upper"

0

repeated char to upper

# function for changing the
# repeated characters to uppercase
def RepeatedUpper(s):
 
    # declaring dictionary
    dic = {}
 
    # Traversing the string
    for i in s:
 
        # If the character is already
        # present in dictionary then increment
        # the frequency of the character
        if i in dic:
            dic[i] = dic[i]+1
 
   # If the character is not present in
   # the dictionary then inserting
   # the character in the dictionary
        else:
            dic[i] = 1
    ans = ''
 
    # traversing the string
    for i in s:
 
        # if the frequency of the character is
        # greater than one
        if dic[i] > 1:
 
            # change into uppercase
            i = i.upper()
 
        # appending each character to the ans
        ans = ans+i
    return ans
 
 
# Driver code
s = 'geeks for geeks'
# function call
print(RepeatedUpper(s))
Posted by: Guest on April-28-2022

Code answers related to "repeated char to upper"

Browse Popular Code Answers by Language