Given the next word:
ABCABACBABACACBACBAC
What would be the most efficient way to count the letters that appear in the word using python?
(Solution: A:8, B:6, C:6)
You can solve it like this:
>>> def counter(in_str):
... out_dict = dict()
... for char in in_str:
... if char in out_dict:
... out_dict[char] += 1
... else:
... out_dict[char] = 1
... return out_dict
...
>>> counter("ABCABACBABACACBACBAC")
{'A': 8, 'B': 6, 'C': 6}
>>>
If you want to give a try on how to implement things.