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) # Der Standardwert von nicht vorhandenen Schlüsseln ist 0 for word in words: word_counts[word] += 1 print(word_counts)
Result:
Report an issue