假设我有一个字典,其中包含单词和短语的形式如下。
我希望能够根据给定的关键值计算所有单词/短语的频率。
例如:仅单词“home”的频率需要为2(因为它在3和4个关键值中都出现了)。其余所有单词/短语的频率均为1。
我尝试使用
Counter(index.values()).most_common()
是否存在一种用Python实现这种计算的方法?
{
('The brown fox',): [0], ('the race',): [0], ('Apple',): [1],
('a company Apple',): [1], ('iphone',): [1], ('Paris',): [2],
('Delhi',): [2], ('London',): [2], ('world cities',): [2],
('home',): [3, 4], ('order delivery food',): [3], ('simple voice command',): [3],
('dinner',): [3], ('a long day',): [3], ('work',): [3],
('teams',): [4], ('goal home',): [4], ('fox world',): [5],
('a world class company',): [5], ('A geyser heating system',): [6], ('a lot',): [7],
('the book Python',): [7], ('an amazing language',): [7], ('i',): [8],
('a good boy',): [8], ('Team Performance',): [9], ('Revolv central automation device',): [10],
('the switch way',): [11], ('play children',): [12]
}
我希望能够根据给定的关键值计算所有单词/短语的频率。
例如:仅单词“home”的频率需要为2(因为它在3和4个关键值中都出现了)。其余所有单词/短语的频率均为1。
我尝试使用
Counter(index.values()).most_common()
是否存在一种用Python实现这种计算的方法?