Word Count Dictionary
Word Count Dictionary
Compute a word frequency dictionary from a list of tokenized sentences. Input is a list of sentences, where each sentence is itself a list of tokens.
Examples
Input: [["i", "love", "ml"], ["i", "love", "coding"]]
Output: {"i": 2, "love": 2, "ml": 1, "coding": 1}
Input: [["hello", "hello"], ["world"]]
Output: {"hello": 2, "world": 1}
Input: []
Output: {}
Hint 1
Initialize an empty dictionary, then iterate through all sentences and words to build counts.
Requirements
- Count every token across all sentences
- Keys are words (strings), values are integer counts
- Do not mutate the input sentences
Constraints
- 0 ≤ len(sentences) ≤ 10,000
- Each sentence length ≤ 1,000
- Python only (dicts/lists)
Try Similar Problems
Log in to take notes on this problem
Accepts: array
Word Count Dictionary
Word Count Dictionary
Compute a word frequency dictionary from a list of tokenized sentences. Input is a list of sentences, where each sentence is itself a list of tokens.
Examples
Input: [["i", "love", "ml"], ["i", "love", "coding"]]
Output: {"i": 2, "love": 2, "ml": 1, "coding": 1}
Input: [["hello", "hello"], ["world"]]
Output: {"hello": 2, "world": 1}
Input: []
Output: {}
Hint 1
Initialize an empty dictionary, then iterate through all sentences and words to build counts.
Requirements
- Count every token across all sentences
- Keys are words (strings), values are integer counts
- Do not mutate the input sentences
Constraints
- 0 ≤ len(sentences) ≤ 10,000
- Each sentence length ≤ 1,000
- Python only (dicts/lists)
Try Similar Problems
Log in to take notes on this problem
Accepts: array