An idea might be to use all(..)
and a generator:
if all(x in l for x in ['a','b','c','d']):
pass
All takes as input any kind of iterable and checks that for all elements the iterable emits, bool(..)
is True
.
Now within all
we use a generator. A generator works like:
<expr> for <var> in <other-iterable>
(with no braces)
It thus takes every element in the <other-iterable>
and calls the <expr>
on it. In this case the <expr>
is x in l
, and x
is the <var>
:
# <var>
# |
x in l for x in ['a','b','c','d']
#\----/ \---------------/
#<expr> <other-iterable>
Further explanation of generators.