13

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.

Community
  • 1
  • 1
user1705279
  • 141
  • 1
  • 2
  • 7

2 Answers2

27

Use any():

if any(s in some_string for s in example):
    # at least one of the elements is a substring of some_string
Andrew Clark
  • 202,379
  • 35
  • 273
  • 306
-2

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.

pram
  • 1,484
  • 14
  • 17
  • I think the question was to check whether they’re in a string, not whether any of them is a string. –  Sep 28 '12 at 18:41