I have an operator
if "1111111" in players or "0000000" in players or "blablabla" in players: do something
How to write shorter?
if any(x in players for x in ("1111111", "0000000", "blablabla")): # do something
If you intend to perform many such membership checks, you might consider making players into a set that should not potentially cross the entire sequence on each check.
players
set
You can use any() :
any()
things = ["1111111", "0000000", "blablabla"] if any(thing in players for thing in things):
if any(a in players for a in list_of_tests): #something pass
If you are using numpy.any() , you need to convert the generator to a list first.
numpy.any()
if np.any([a in players for a in list_of_tests]): #something pass