An idea might be to use all(..)
and a generator:
if all(x in l for x in ['a','b','c','d']): pass
Everything takes any type of iteration as input and checks that for all elements emitted by iterable, bool(..)
is True
.
Now in all
we use a generator. The generator works like:
<expr> for <var> in <other-iterable>
(without curly braces)
Thus, it takes each element in <other-iterable>
and calls <expr>
on it. In this case, <expr>
is x in l
, and x
is <var>
:
# <var> # | x in l for x in ['a','b','c','d'] #\----/ \---------------/ #<expr> <other-iterable>
Further explanation of generators .
source share