Problems
Loading...
1 / 1

Word Count Dictionary

NLP
Easy

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.

Loading visualization...

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