-1

I have a string S and strings s_1, s_2, s_3, s_4.

I want to do the following:

if s_1 not in S and s_2 not in S and s_3 not in S and s_4 not in s:
   code...

Is there a shorthand for this?

Something like

If s_1, s_2, s_3, s_4 not in S:
   code...

But this doesn't seem to work?

khelwood
  • 52,115
  • 13
  • 74
  • 94
the man
  • 871
  • 1
  • 5
  • 10

1 Answers1

2

You can youse list comprehension (read more about it here:

lst = [s_1, s_2, s_3, s_4]

in case you want that all s_... are not in S, use:

all(x not in S for x in lst)

in case it is enough if one s_... is not in S, use:

any(x not in S for x in lst)
Andreas
  • 7,669
  • 3
  • 9
  • 30