Source Code:
(back to article)
from collections import defaultdict sentence = "The quick brown fox jumps over the lazy dog" words = sentence.split() word_counts = defaultdict(int) # default value of nonexistent keys is 0 for word in words: word_counts[word] += 1 print(word_counts)
Result:
Report an issue