marou95thebest
marou95thebest

Reputation: 199

Include 2 conditions in a for loop in python

i have this line:

logical= [value in line for value in Dictionnary["substance_name"].values]

that gave me this error:

TypeError: 'in <string>' requires string as left operand, not NoneType

This is probably due to some gaps in my dictionnary.

So to fix it I thought about adding this:

logical= [value in line for value in Dictionnary["substance_name"].values and value not None]

By the synthax seems to be incorrect. How can I express it correctly? I edited my code:

logical= [value in line for value in DictionnaireMedicHUG["substance_name"].values] 
            if logical != None:

I am still getting the same error

Upvotes: 0

Views: 71

Answers (1)

Higs
Higs

Reputation: 404

Try this:

logical = [value in line for value in DictionnaireMedicHUG["substance_name"].values if logical is not None] 

Upvotes: 1

Related Questions