Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Short if statement with or in Python

I have if statement

if "1111111" in players or "0000000" in players or "blablabla" in players:
    do something

How to write in short ?

like image 244
lifez Avatar asked Dec 26 '22 05:12

lifez


1 Answers

if any(x in players for x in ("1111111", "0000000", "blablabla")):
    # do something

If you are going to be doing a lot of these membership checks you may consider making players into a set which doesn't need to potentially traverse the entire sequence on each check.

like image 60
jamylak Avatar answered Dec 28 '22 22:12

jamylak