I am parsing a long string of text and calculating the number of times each word occurs in Python. I have a function that works but I am looking for advice on whether there
Use collections.Counter:
>>> from collections import Counter >>> test = 'abc def abc def zzz zzz' >>> Counter(test.split()).most_common() [('abc', 2), ('zzz', 2), ('def', 2)]