basically, without imports:
is_letter is a function to decide if something is a letter,
so that you can count other things than the usual english letters
def add_or_init(dictionary, c):
if(c in dictionary):
dictionary[c]+=1
else:
dictionary[c]=1
def count_one_letter(dictionary, c, is_letter):
if is_letter(c):
add_or_init(dictionary, c)
def count_letters(dictionary, string, is_letter):
for c in string:
count_one_letter(dictionary, c, is_letter)
return dictionary
#count all characters
count_letters(dict(),'aaabbbcccffffd eee fff ggg',lambda x: True)
# => {'a': 3, ' ': 3, 'c': 3, 'b': 3, 'e': 3, 'd': 3, 'g': 3, 'f': 3}