我试图遍历tsv文件的每一行,并检查字典中是否存在每个单词。该功能可以从每一行的每个内容中提取单词,但是在查找字典中是否存在单词时会失败。
dic = {'films': '0', 'adapted': '1', 'from': '2', 'comic': '3', 'books': '4'}
csv文件格式= [1\tcontent]
def extract_feature(filename):
with open(filename) as tsv:
reader = csv.reader(tsv, delimiter = "\t")
for row in reader:
for word in row[1].split():
if word in dict:
print(word)
答案 0 :(得分:0)
if word in dict:
dict
是字典类型,类似于list
,int
,float
等。
请勿使用dict
作为变量名。