mercredi 30 décembre 2020

python if statement not working correctly with gensim language model

If statement not working properly when else added. The else statement prints when the if statement should.

Doesnt work:

variable = 'programming'

for i, word in enumerate(wv.vocab):
    if word == variable:
        print("Is ready to be measured")
    else:
        print("text to clean")
        #do this
        break

The below works showing the term variable is in the model wv.vocab

variable = 'programming'

for i, word in enumerate(wv.vocab):
    if word == variable:
        print("Is ready to be measured")
    #else:
        #print("text to clean")
        #do this
        break

When the variable is changed to something not in the model it does not work.

variable = 'programmings'

for i, word in enumerate(wv.vocab):
    if word == variable:
        print("Is ready to be measured")
    #else:
        #print("text to clean")
        #do this
        break

Aucun commentaire:

Enregistrer un commentaire