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.
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: {}
Initialize an empty dictionary before traversing the nested lists.
Update with counts[word] = counts.get(word, 0) + 1.
Sign in to take notes on this problem
Accepts: array
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.
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: {}
Initialize an empty dictionary before traversing the nested lists.
Update with counts[word] = counts.get(word, 0) + 1.
Sign in to take notes on this problem
Accepts: array