TensorTonic
Problems
Word Count Dictionary
NLP
Easy

Count token frequencies across a list of tokenized sentences. Each sentence is a list of strings. Return one dictionary whose keys are tokens and whose integer values are their total counts across every sentence.

Loading visualization...

Examples

Input: sentences = [["i", "love", "ml"], ["i", "love", "coding"]]

Output: {"i": 2, "love": 2, "ml": 1, "coding": 1}

Explanation: Counts accumulate across both sentences while first-seen key order is preserved.

Input: sentences = [["hello", "hello"], ["world"]]

Output: {"hello": 2, "world": 1}

Input: sentences = []

Output: {}

Hint 1

Initialize an empty dictionary before traversing the nested lists.

Hint 2

Update with counts[word] = counts.get(word, 0) + 1.

Requirements

  • Visit every token in every sentence
  • Accumulate counts across sentence boundaries
  • Leave the nested input lists unchanged
  • Return a dictionary from strings to integers

Constraints

  • sentences is a list of string lists
  • Sentences and the outer list may be empty
  • Use Python only
Try Similar Problems
Remove Stopwords From a Token List in PythonEasyBag-of-Words VectorEasyText Chunking for RAG in PythonEasyBigram Probabilities (Add-1 Smoothing)HardImplement a TF-IDF Vectorizer in PythonHardRNN Step Forward (Tanh Cell)EasyLevenshtein Edit Distance in PythonEasyPerplexity ComputationEasyStemming vs LemmatizationEasyTokenizationEasyRegex Patterns for NLPEasyText NormalizationEasy
Scratchpad

Accepts: array

You must run your code first.
Word Count Dictionary

Word Count Dictionary

NLP
Easy

Count token frequencies across a list of tokenized sentences. Each sentence is a list of strings. Return one dictionary whose keys are tokens and whose integer values are their total counts across every sentence.

Loading visualization...

Examples

Input: sentences = [["i", "love", "ml"], ["i", "love", "coding"]]

Output: {"i": 2, "love": 2, "ml": 1, "coding": 1}

Explanation: Counts accumulate across both sentences while first-seen key order is preserved.

Input: sentences = [["hello", "hello"], ["world"]]

Output: {"hello": 2, "world": 1}

Input: sentences = []

Output: {}

Hint 1

Initialize an empty dictionary before traversing the nested lists.

Hint 2

Update with counts[word] = counts.get(word, 0) + 1.

Requirements

  • Visit every token in every sentence
  • Accumulate counts across sentence boundaries
  • Leave the nested input lists unchanged
  • Return a dictionary from strings to integers

Constraints

  • sentences is a list of string lists
  • Sentences and the outer list may be empty
  • Use Python only
Try Similar Problems
Remove Stopwords From a Token List in PythonEasyBag-of-Words VectorEasyText Chunking for RAG in PythonEasyBigram Probabilities (Add-1 Smoothing)HardImplement a TF-IDF Vectorizer in PythonHardRNN Step Forward (Tanh Cell)EasyLevenshtein Edit Distance in PythonEasyPerplexity ComputationEasyStemming vs LemmatizationEasyTokenizationEasyRegex Patterns for NLPEasyText NormalizationEasy
Scratchpad

Accepts: array

You must run your code first.
Problems
Loading...
1 / 1