Open this example in the interactive library
Source code
from collections import Counter
print(Counter('red blue red'.split()).most_common())Sample output
[('red', 2), ('blue', 1)]
Count words with Counter. A self-contained example using the Python standard library.
Open this example in the interactive library
from collections import Counter
print(Counter('red blue red'.split()).most_common())[('red', 2), ('blue', 1)]