Lets say I have
a = "FIFA 13"
then I writing
"bla" and "13" in a
And result is true... Why? bla is not in the a
Your boolean expression is being evaluated as ("bla") and ("13" in a), non-empty strings evaluate as true, so if "13" in a is true then the entire expression will evaluate as true.
Instead, use all():
all(x in a for x in ("bla", "13"))
Or just check both separately:
"bla" in a and "13" in a
"bla" is true
"13" in a is true
Hence, "bla" and "13" in a is true
What you wanted to write is probably : ("bla" in a) and ("13" in a)
in operator has a higher precedence than the and operator. See: docs.python.org/2/reference/expressions.html#summaryYour code isn't interpreted like it is read:
("bla") and ("13" in a)
"bla" is truthy, so it automatically evaluates to True. "13" in a might be True. False and True evaluates to True, so "bla" isn't really taken into consideration.
You have to be a bit more explicit:
'bla' in a and '13' in a
Or you can use an unreadable one-liner:
all(map(a.__contains__, ('bla', '13')))
For a short-circuiting one-liner, I think you'll have to use itertools.imap instead of map..
operator.contains(), all(map(lambda x:contains(a,x),("bla","12")))
"bla" in a and "13" in a