我把一个文件读入一个列表,然后把它拆分,这样每个单词都在一个列表中。但是,我不想在列表中提到具体的词,我想跳过它们。我把下面写的垃圾清单叫做过滤器清单。你知道吗
这是我的密码:
with open('USConstitution.txt') as f:
lines = f.read().split() #read everything into the list
filterList = ["a","an","the","as","if","and","not"] #define a filterList
for word in lines:
if word.lower() not in filterList:
word.append(aList) #place them in a new list called aList that does not contain anything in filterList
print(aList) #print that new list
我得到这个错误:
AttributeError: 'str' object has no attribute 'append'
有人能帮忙吗?谢谢
你需要付出
列表对象只有
append
属性。你还需要先申报名单。只有你才能把这些项目附加到列表中。你知道吗伊恩
相关问题 更多 >
编程相关推荐