Append digits to the end of duplicate strings to make all strings in an array unique | Function to replace duplicate strings by alphanumeric strings to make all strings in the array unique ; Store the frequency of strings ; Iterate over the array ; For the first occurrence , update the frequency count ; Otherwise ; Append frequency count to end of the string ; Print the modified array ; Driver Code ; Function Call
def replaceDuplicates ( names ) : NEW_LINE INDENT hash = { } NEW_LINE for i in range ( 0 , len ( names ) ) : NEW_LINE INDENT if names [ i ] not in hash : NEW_LINE INDENT hash [ names [ i ] ] = 1 NEW_LINE DEDENT else : NEW_LINE INDENT count = hash [ names [ i ] ] NEW_LINE hash [ names [ i ] ] += 1 NEW_LINE names [ i ] += str ( count ) NEW_LINE DEDENT DEDENT for i in range ( 0 , len ( names ) ) : NEW_LINE INDENT print ( names [ i ] , end = ' ▁ ' ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT str1 = [ " aa " , " bb " , " cc " , " bb " , " aa " , " aa " , " aa " ] NEW_LINE replaceDuplicates ( str1 ) NEW_LINE DEDENT