简体   繁体   中英

TypeError: argument of type 'type' is not iterable in python

I tried to go through each line of the tsv file and check if each word exists in a dictionary. The function can extract word from each content in each row, but it fails when it looks for if a word exists in a dictionary.

dic = {'films': '0', 'adapted': '1', 'from': '2', 'comic': '3', 'books': '4'}

The csv file format = [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)
if word in dict:

dict is the dictionary type, similar to list , int , float , etc.

Don't use dict as a variable name.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM