I have relatively complicated if statements that return True
if a target string contains a keyword (also a string). Is there a way that as an elif
I search for the keyword in multiple target strings?
This is my sample code:
a = 'i am foo'
b = 'keyword could also be in here'
if 'foo' in 'b':
out = 1
elif 'foo' in [a,b]:
out = 2
else:
out = 3
Current behavior: returns 3 Expected behavior: return 2
I know that I could do elif 'foo' in a or 'foo' in b
but my conditions are already lengthy with any and all statements so that the code becomes rather unreadable when I solve the issue with or
.
Basically, I'm looking for a pythonic way to do this (only not in JavaScript).
Thanks!