Python multi-lists iteration
iteration, list, python
Solution
`itertools.product()` does exactly this:
for a, b in itertools.product(list1, list2):
foo(a, b)
It can handle an arbitrary number of iterables, and in that sense is more general than nested `for` loops.
Problem
Is there a clever way to iterate over two lists in Python (without using list comprehension)? I mean, something like this: ``` # (a, b) is the cartesian product between the two lists' elements for a, b in list1, list2: foo(a, b) ``` instead of: ``` for a in list1: for b in list2: foo(a, b) ```