Created
October 17, 2024 22:51
-
-
Save mschulz/a811b65de6a86002f8e95d7f0aa5acc7 to your computer and use it in GitHub Desktop.
Optimize Multiple Conditions with any and all
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Bad | |
if (a > 5) and (b < 10) and (c == 20): | |
pass | |
# Good | |
if all([a > 5, b < 10, c == 20]): | |
pass | |
# Or for the opposite | |
if any([a > 5, b < 10, c == 20]): | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment