Skip to content

Instantly share code, notes, and snippets.

@mschulz
Created October 17, 2024 22:51
Show Gist options
  • Save mschulz/a811b65de6a86002f8e95d7f0aa5acc7 to your computer and use it in GitHub Desktop.
Save mschulz/a811b65de6a86002f8e95d7f0aa5acc7 to your computer and use it in GitHub Desktop.
Optimize Multiple Conditions with any and all
# 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