-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
  • 55,782
  • 14
  • 81
  • 108
the man
  • 1,131
  • 1
  • 8
  • 19

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
  • 8,694
  • 3
  • 14
  • 38