gpt4 book ai didi

python - Python语法错误: blank space

转载 作者:行者123 更新时间:2023-12-03 08:21:58 28 4
gpt4 key购买 nike

我是python新手,此代码旨在打印出MusicTaste.csv文件中的前100个常用单词并将其打印在表格中。我已经解决了过去的语法错误,但之前从未见过此错误。

请参见下面的代码

import re
from collections import Counter
from prettytable import PrettyTable

words = re.findall('\w+',open('MusicTaste2.csv').read().lower())
for label, data in ('Word', words) THE_ERROR_APPEARS_HERE_BLANK_SPACE

pt = PrettyTable(field_names=[label, 'Count'])
c = Counter(words)
[ pt.add_row(kv) for kv in c.most_common()[:100]

print pt

最佳答案

import re
from collections import Counter
from prettytable import PrettyTable

words = re.findall('\w+',open('MusicTaste2.csv').read().lower())
for label, data in ('Word', words):
pt = PrettyTable(field_names=[label, 'Count'])
c = Counter(words)
[pt.add_row(kv) for kv in c.most_common()[:100]]
print (pt)

第一个问题是 indent您的代码正确

第二行缺少 :
for label, data in ('Word', words):

我看到的第三个问题是以下行中缺少 ]
[pt.add_row(kv) for kv in c.most_common()[:100]]

关于python - Python语法错误: blank space,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29028224/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com