Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from collections import defaultdict
- list_words = str.split(' ')
- ddict = defaultdict(int)
- for k in list_words:
- ddict[k] += 1+= 1
- from collections import Counter
- s = "1 Let's try to be Good. 2 Being good doesn't make sense. 3 Good is always good."
- s1 = s.split(' ')
- counts = Counter(s1)
- print(counts)
- Counter({'': 6, '1': 1, "Let's": 1, 'try': 1, 'to': 1, 'be': 1, 'Good.': 1, '2': 1, 'Being': 1, 'good': 1, "doesn't": 1, 'make': 1, 'sense.': 1, '3': 1, 'Good': 1, 'is': 1, 'always': 1, 'good.': 1})
Add Comment
Please, Sign In to add comment