Possible Duplicate:
Check if multiple strings exist in another string
Check to ensure a string does not contain multiple values
So guys. If i have
example = "1", "2", "3"
How would i check if any of the items are in a string.
Possible Duplicate:
Check if multiple strings exist in another string
Check to ensure a string does not contain multiple values
So guys. If i have
example = "1", "2", "3"
How would i check if any of the items are in a string.
Use any()
:
if any(s in some_string for s in example):
# at least one of the elements is a substring of some_string
One example:
>>> example = "1", 2, "3"
>>> str in [type(entry) for entry in example]
will return True if there was an str in the tuple.