mercredi 24 février 2021

Python simple not in statement not working [duplicate]

In python I am trying to run this code:

    blacklist = ['hello', 'man']
    for word in open("text.txt"):
      if word not in blacklist:
          print(word)

In text.txt I have

test hello man

I would like the output to be:

test

But - it just returns the text of text.txt! What is the issue?

Aucun commentaire:

Enregistrer un commentaire