I have a list that looks like this:
list = ['for','and','with','be in']
And I have implemented some code that checks to see if the above words are contained within a string:
if any(word in stringVar for word in list):
\\logic
The above works as expected, however, I wan't to have some phrases excluded from the above as follows:
exc_list = ['for every','for each']
So essentially, I want to change my if statement so that it returns true if and, with and be in are contained within the stringVar OR for is contained within the stringVar but not when it is followed by every or each.
I had originally implemented this:
if any(word in stringVar for word in list) and any(word not in stringVar for word in exc_list):
\\logic
But this will not work as expected if the stringVar is equal to 'will be in every day for each week'.
To confirm, I want to return true at all times when and, with and be in are contained within the stringVar, even if for each/every is to appear too. The exclusions should only come into effect when for appears within stringVar