我正在一个项目中尝试在txt文件中查找所有唯一单词,但是我似乎被卡在编码从列表中删除所有标点符号的行后发生的错误所困扰。
到目前为止,这是我的代码:
// index.ts
export { BaseClass } from "./base";
export { DerivedClass } from "./derived";
运行此命令后,我收到一条错误消息:如果未检查该单词:
import string
a = open('blank.txt')
def main():
check = []
for line in a:
lines = line.lower()
words = line.split()
for word in words:
if word not in check:
check.append(word)
check = [''.join(c for c in s if c not in string.punctuation) for s in check]
check = [s for s in x if s]
check.sort()
print(check)
if __name__ == '__main__':
main()
想知道是否有人可以提供帮助。谢谢