dimanche 22 août 2021

How to check a string does not contain two different substrings with only one condition?

I have a string called name. I am interested in cases where name does not contain neither 'bias' nor 'bn'. I can implement it using two conditions in two ways as follows:

if 'bias' not in name and 'bn' not in name:
   pass

Or using Demorgan's law as follows:

if not ('bias' in name or 'bn' in name):
   pass

Note that name has more characters than 'bias' or 'bn' so we cannot have name not in {'bias', bn'} as the one-condition case.

Question: How can we check whether name string does not contain neither 'bias' nor 'bn' with one in or one condition?

Aucun commentaire:

Enregistrer un commentaire