from collections import Counter sentence = 'teste conaz' counter = Counter() for word in sentence.split(): counter.update(word) print(counter.most_common()) print(dict(counter.most_common()))
Standard input is empty
[('t', 2), ('e', 2), ('s', 1), ('c', 1), ('o', 1), ('n', 1), ('a', 1), ('z', 1)] {'t': 2, 'e': 2, 's': 1, 'c': 1, 'o': 1, 'n': 1, 'a': 1, 'z': 1}