Python-exercises/count-words.py

10 lines
No EOL
413 B
Python

import collections
text = "the quick brown fox jumps over the lazy dog the fox"
words = text.split()
char = text.replace(' ', '')
text_collect = collections.Counter(words).most_common(3)
print(f"words: {len(words)}, char: {len(char)} top 3: {text_collect}")
#my outpout: words: 11, char: 41 top 3: [('the', 3), ('fox', 2), ('quick', 1)]
#output: 11 caracteres: 43 top 3: [('the', 3), ('fox', 2), ('quick', 1)]ß