Iterate over characters of the string
for ch in str : NEW_LINE INDENT if ch in mp . keys ( ) : NEW_LINE INDENT mp [ ch ] += 1 NEW_LINE DEDENT else : NEW_LINE INDENT mp [ ch ] = 1 NEW_LINE DEDENT DEDENT