I have this code:
values="2"
content=["line1","line2","line3"]
for line in content:
if values not in line:
print(line)
which successfully prints out items of content when value 2 is not in those items:
line1
line3
Practically, I am grabbing content out of a file.readlines() method.
Now, I am stuck when I have to compare more than one value against each of the content lines:
values=["2","3"]
Again, I need to check if 2 or 3 are in each of the content lines and print the line when they are not.
I came up with this:
values=["2","3"]
content=["line1","line2","line3"]
for line in content:
for value in values:
if value not in line:
print(line)
But that would normally return this:
line1
line1
line2
line3
I would expect only line1 to be printed out. Any workaround to this?
Aucun commentaire:
Enregistrer un commentaire