jeudi 31 janvier 2019

TypeError: NoneType is unsubscriptable - IF statement

I am trying to find fuzzy string matches for university names and print a certain score (10, 5 ,3) to a csv each time depending on what list the closest match came from.

data = ["MIT", "Stanford",...]

Data1 = ['MASSACHUSETTS INSTITUTE OF TECHNOLOGY (MIT)'], ['STANFORD UNIVERSITY'],...

So far I have tried:

1 for uni in data:
2    hit = process.extractOne(str(uni[1]), data1, scorer = fuzz.token_set_ratio, score_cutoff = 90)
3    if float(hit[1]) < 100:
4       print("not found")
5    else:
        print("Closest match for " + str(uni[1]) + " is " + str(hit[0]) " + "score: 10")

At this point I get the TypeError: NoneType is unsubscriptable for line 3

I have checked the type of my variable:

print(type(hit)) #I was getting tuple now NoneType...
print(len(hit))  # Was getting 2 now unsubscriptable
print(float(hit[1])) # 100

As I understood this error comes up when a variable is not the type one thinks it is. Any idea how to resolve this issue? Many thanks

Aucun commentaire:

Enregistrer un commentaire