python-3.x - 从我的 wordcloud 中排除无趣的单词我缺少什么?
问题描述
def calculate_frequencies(file_contents):
# Here is a list of punctuations and uninteresting words you can use to process your text
punctuations = '''!()-[]{};:'"\,<>./?@#$%^&*_~'''
uninteresting_words = ["the", "a", "to", "if", "is", "it", "of", "and", "or", "an", "as", "i", "me", "my", \
"we", "our", "ours", "you", "your", "yours", "he", "she", "him", "his", "her", "hers", "its", "they", "them", \
"their", "what", "which", "who", "whom", "this", "that", "am", "are", "was", "were", "be", "been", "being", \
"have", "has", "had", "do", "does", "did", "but", "at", "by", "with", "from", "here", "when", "where", "how", \
"all", "any", "both", "each", "few", "more", "some", "such", "no", "nor", "too", "very", "can", "will", "just"]
# LEARNER CODE START HERE
dict = {}
new_list = []
for word in file_contents.lower().split():
if word.isalpha not in uninteresting_words:
new_list.append(word)
for word in new_list:
if word not in dict.keys():
dict[word] = new_list.count(word)
#wordcloud
cloud = wordcloud.WordCloud()
cloud.generate_from_frequencies(dict)
return cloud.to_array()
我已经修复了我的代码,因此它不会返回任何错误,除非它仍然返回一个带有无趣单词的词云。假设其他一切都是正确的,我觉得if word.isalpha not in uninteresting_words:
应该照顾它。