#-*-coding:utf-8-*-#取一个字符串中最多出现次数的词ImportRe fromCollectionsImportCountermy_str="""Simple are better than Complex.complex is better than complicated. Flat is better than nested. Sparse is better than dense. Readability counts. Special cases aren ' t special enough to break the rules. Although practicality beats purity. Errors should never pass silently. Unless explicitly silenced. In the face of ambiguity, refuse the temptation to guess. There should is one--and preferably only one--obvious the-do it. Although that's obvious at first unless you ' re dutch.now is better than never. Although never is often better than *right* now. If the implementation is hard to explain, it's a bad idea. If the implementation is easy to explain, it could be a good idea. Namespaces is one honking great idea – let's do more than those!"""Word_count= Counter (Re.split ('[.,; ~!-<>/|@#$%^&*?\n\t]', my_str))#take non-empty top eight most wordsMost_11 = [x forXinchWord_count.most_common (8)ifX[0]! =""]#take the top eight most words directlyPrintWord_count.most_common (8)Print(Most_11) forIinchMost_11:PrintI[0]
Python takes a word with a maximum number of occurrences in a string