Some usage of Python Collections Library:

  • Counter:
from collections import defaultdict, Counter

st = "aaaccvvvvvbbb"
for key, val in dict(Counter(st)).items():
print(key,val)
  • defaultdict:
from collections import defaultdict, Counter
d = defaultdict(list) # {key: list}. set, int,float,str etc. values in dict possible
print(d.get(11, -1)) # -1/None/anydefaultvalue for if key not found in d
d[11] = 'Eleven'
print(d.get(11, -1))