Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/332.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 为什么第13行出现语法错误? def计算频率(文件内容): #下面是一个标点符号和无趣单词的列表,您可以使用它们来处理文本 标点符号=“”!()-[]{};:'"\,./?@#$%^&*_~''' 无趣的单词=[“the”,“a”,“to”,“if”,“is”,“it”,“of”,“and”,“or”,“an”,“as”,“i”,“me”,“my”\ “我们”、“我们的”、“我们的”、“你”、“你的”、“你的”、“他”、“她”、“他”、“他的”、“她”、“她的”、“它”、“它们”、“它们”\ “他们”、“什么”、“哪个”、“谁”、“谁”、“这个”、“那个”、“我”、“是”、“是”、“是”、“是”、“是”、“是”、“被”、“被”、“被”、“存在”\ “have”,“has”,“had”,“do”,“does”,“did”,“but”,“at”,“by”,“with”,“from”,“here”,“when”,“where”,“how”\ “全部”、“任何”、“两者”、“各自”、“很少”、“更多”、“一些”、“这样”、“不”、“也”、“非常”、“可以”、“将”、“只是”] dict={} x=[file_contents.lower().split()] 新列表=[] 对于x中的word.isalpha: 如果word.isalpha不是无趣的单词: 新建列表.append(word.isalpha) 对于新列表中的单词: 如果单词不在dict.keys()中: dict[word]=新列表计数(word) #wordcloud cloud=wordcloud.wordcloud() cloud.generate_from_frequencies() 返回cloud.to_数组() 文件“”,第13行 如果word.isalpha不是无趣的单词: ^ SyntaxError:无效语法_Python - Fatal编程技术网

Python 为什么第13行出现语法错误? def计算频率(文件内容): #下面是一个标点符号和无趣单词的列表,您可以使用它们来处理文本 标点符号=“”!()-[]{};:'"\,./?@#$%^&*_~''' 无趣的单词=[“the”,“a”,“to”,“if”,“is”,“it”,“of”,“and”,“or”,“an”,“as”,“i”,“me”,“my”\ “我们”、“我们的”、“我们的”、“你”、“你的”、“你的”、“他”、“她”、“他”、“他的”、“她”、“她的”、“它”、“它们”、“它们”\ “他们”、“什么”、“哪个”、“谁”、“谁”、“这个”、“那个”、“我”、“是”、“是”、“是”、“是”、“是”、“是”、“被”、“被”、“被”、“存在”\ “have”,“has”,“had”,“do”,“does”,“did”,“but”,“at”,“by”,“with”,“from”,“here”,“when”,“where”,“how”\ “全部”、“任何”、“两者”、“各自”、“很少”、“更多”、“一些”、“这样”、“不”、“也”、“非常”、“可以”、“将”、“只是”] dict={} x=[file_contents.lower().split()] 新列表=[] 对于x中的word.isalpha: 如果word.isalpha不是无趣的单词: 新建列表.append(word.isalpha) 对于新列表中的单词: 如果单词不在dict.keys()中: dict[word]=新列表计数(word) #wordcloud cloud=wordcloud.wordcloud() cloud.generate_from_frequencies() 返回cloud.to_数组() 文件“”,第13行 如果word.isalpha不是无趣的单词: ^ SyntaxError:无效语法

Python 为什么第13行出现语法错误? def计算频率(文件内容): #下面是一个标点符号和无趣单词的列表,您可以使用它们来处理文本 标点符号=“”!()-[]{};:'"\,./?@#$%^&*_~''' 无趣的单词=[“the”,“a”,“to”,“if”,“is”,“it”,“of”,“and”,“or”,“an”,“as”,“i”,“me”,“my”\ “我们”、“我们的”、“我们的”、“你”、“你的”、“你的”、“他”、“她”、“他”、“他的”、“她”、“她的”、“它”、“它们”、“它们”\ “他们”、“什么”、“哪个”、“谁”、“谁”、“这个”、“那个”、“我”、“是”、“是”、“是”、“是”、“是”、“是”、“被”、“被”、“被”、“存在”\ “have”,“has”,“had”,“do”,“does”,“did”,“but”,“at”,“by”,“with”,“from”,“here”,“when”,“where”,“how”\ “全部”、“任何”、“两者”、“各自”、“很少”、“更多”、“一些”、“这样”、“不”、“也”、“非常”、“可以”、“将”、“只是”] dict={} x=[file_contents.lower().split()] 新列表=[] 对于x中的word.isalpha: 如果word.isalpha不是无趣的单词: 新建列表.append(word.isalpha) 对于新列表中的单词: 如果单词不在dict.keys()中: dict[word]=新列表计数(word) #wordcloud cloud=wordcloud.wordcloud() cloud.generate_from_frequencies() 返回cloud.to_数组() 文件“”,第13行 如果word.isalpha不是无趣的单词: ^ SyntaxError:无效语法,python,Python,我收到一个语法错误,我不希望得到帮助。isalpha是一个返回布尔值(真\假)的函数。您需要将放在第13行的中: File "<ipython-input-11-ea9576de222d>", line 13 if word.isalpha not uninteresting_words: ^ SyntaxError: invalid syntax def计算频率(文件内

我收到一个语法错误,我不希望得到帮助。

isalpha是一个返回布尔值(真\假)的函数。

您需要将
放在第13行的
中:

File "<ipython-input-11-ea9576de222d>", line 13
    if word.isalpha not uninteresting_words:
                                          ^
SyntaxError: invalid syntax
def计算频率(文件内容):
#下面是一个标点符号和无趣单词的列表,您可以使用它们来处理文本
标点符号=''!()-[]{};:'',./?@$%^&*.''
无趣的单词=[“the”,“a”,“to”,“if”,“is”,“it”,“of”,“and”,“or”,“an”,“as”,“i”,“me”,“my”\
“我们”、“我们的”、“我们的”、“你”、“你的”、“你的”、“他”、“她”、“他”、“他的”、“她”、“她的”、“它”、“它们”、“它们”\
“他们”、“什么”、“哪个”、“谁”、“谁”、“这个”、“那个”、“我”、“是”、“是”、“是”、“是”、“是”、“是”、“被”、“被”、“被”、“存在”\
“have”,“has”,“had”,“do”,“does”,“did”,“but”,“at”,“by”,“with”,“from”,“here”,“when”,“where”,“how”\
“全部”、“任何”、“两者”、“各自”、“很少”、“更多”、“一些”、“这样”、“不”、“也”、“非常”、“可以”、“将”、“只是”]
dict={}
x=[file_contents.lower().split()]
新列表=[]
对于x中的word.isalpha:
//这里。。。。
如果word.isalpha不是用无趣的词:
新建列表.append(word.isalpha)
对于新列表中的单词:
如果单词不在dict.keys()中:
dict[word]=新列表计数(word)
#wordcloud
cloud=wordcloud.wordcloud()
cloud.generate_from_frequencies()
返回cloud.to_数组()

您在
中缺少了一个
,您在
中忘记了
(您在后面的
单词不在dict.keys()中的测试中包括了该测试)。哇。。谢谢大家。我想我真的需要注意。这是真的,会使代码行为不正确,但与
SyntaxError
完全无关。
File "<ipython-input-11-ea9576de222d>", line 13
    if word.isalpha not uninteresting_words:
                                          ^
SyntaxError: invalid syntax
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"]
dict = {}
x = [file_contents.lower().split()]
new_list = []
for word.isalpha in x:
    // Here....
    if word.isalpha not in uninteresting_words:
        new_list.append(word.isalpha)

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()
return cloud.to_array()