以下示例是关于Python中包含如何在Python中找到一个字符串中重复率最高的词用法的示例代码,想了解如何在Python中找到一个字符串中重复率最高的词的具体用法?如何在Python中找到一个字符串中重复率最高的词怎么用?如何在Python中找到一个字符串中重复率最高的词使用的例子?那么可以参考以下相关源代码片段来学习它的具体使用方法。
from collections import Counter
# Example phrase
phrase = "John is the son of John second. Second son of John second is William second."
split_phrase = phrase.split()
# create counter object
Counter = Counter(split_phrase)
most_occured_words = Counter.most_common(4)
print(most_occured_words)
本文地址:https://www.itbaoku.cn/snippets/785556.html