Last active
August 8, 2023 18:39
-
-
Save e-dreyer/81b5bc96c90926939ba8057109dfb202 to your computer and use it in GitHub Desktop.
Improve Python loops with product()
This file contains 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
list_a = [1, 2020, 70] | |
list_b = [2, 4, 7, 2000] | |
list_c = [3, 70, 7] | |
for a in list_a: | |
for b in list_b: | |
for c in list_c: | |
if a + b + c == 2077: | |
print(a, b, c) |
This file contains 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
from itertools import product | |
list_a = [1, 2020, 70] | |
list_b = [2, 4, 7, 2000] | |
list_c = [3, 70, 7] | |
for a, b, c in product(list_a, list_b, list_c): | |
if a + b + c == 2077: | |
print(a, b, c) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment