Skip to content

Instantly share code, notes, and snippets.

@e-dreyer
Last active August 8, 2023 18:39
Show Gist options
  • Save e-dreyer/81b5bc96c90926939ba8057109dfb202 to your computer and use it in GitHub Desktop.
Save e-dreyer/81b5bc96c90926939ba8057109dfb202 to your computer and use it in GitHub Desktop.
Improve Python loops with product()
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)
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