Nov-13-2023, 12:06 PM
(This post was last modified: Nov-13-2023, 12:06 PM by Pedroski55.)
What happens if a word repeats? What about punctuation? Lose the punctuation?
I think there are already modules for doing this kind of thing.
I think there are already modules for doing this kind of thing.
from collections import Counter sentence = "All work and no play makes Jack a dull boy. Jack is a dull boy. Work makes him dull." words = sentence.split() wordCount = Counter(words)
Output:Counter({'Jack': 2, 'a': 2, 'dull': 2, 'boy.': 2, 'All': 1, 'work': 1, 'and': 1, 'no': 1, 'play': 1, 'makes': 1, 'is': 1})
type(wordCount)
Output:<class 'collections.Counter'>
wordCount['Jack']
Output:2