Print characters and their frequencies in order of occurrence | Python3 implementation to print the characters and frequencies in order of its occurrence ; Store all characters and their frequencies in dictionary ; Print characters and their frequencies in same order of their appearance ; Print only if this character is not printed before . ; Driver Code
def prCharWithFreq ( str ) : NEW_LINE INDENT d = { } NEW_LINE for i in str : NEW_LINE INDENT if i in d : NEW_LINE INDENT d [ i ] += 1 NEW_LINE DEDENT else : NEW_LINE INDENT d [ i ] = 1 NEW_LINE DEDENT DEDENT for i in str : NEW_LINE INDENT if d [ i ] != 0 : NEW_LINE INDENT print ( " { } { } " . format ( i , d [ i ] ) , end = " ▁ " ) NEW_LINE d [ i ] = 0 NEW_LINE DEDENT DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT str = " geeksforgeeks " ; NEW_LINE prCharWithFreq ( str ) ; NEW_LINE DEDENT ' NEW_LINE