《权力的游戏》是一部由大卫·贝尼奥夫和D。B维斯 对于HBO。该剧是在美国其他地方贝尔法斯特制作和拍摄的 英国
import re
new_text = ''
punctuations = '''!.,'''
for character in Text:
if character not in punctuations:
new_text = new_text + character
from collections import Counter
split_text = Text.split(' ')
count = Counter(split_text)
most_freq_word_new = [key for key,valu in count.items() if valu == max(count.values())]
for index, word in enumerate(split_text):
for i in most_freq_word_new:
if word == i:
print (word)
#print (index)
suffix_word = split_text[index + 1]
prefix_word = split_text[index - 1]
print (suffix_word)
print (prefix_word)
我的输出
and
D
Benioff
and
filmed
produced
in
Belfast
filmed
in
the
elsewhere
我的期望输出
{and:['D','Benioff','filmed','produced'],
in:['Belfast','filmed','the','elsewhere']}
这是一种使用
dict
的方法演示:
输出:
相关问题 更多 >
编程相关推荐