Combine Nested For Loops In Python
Suppose I have a nested loop of the form: for i in List1: for j in List2: DoSomething(i,j) Can it be done as follows: for i,j in combine(List1, List2): DoSomething
Solution 1:
You can use itertools.product
import itertools
for i,j in itertools.product(List1, List2):
DoSomething(i,j)
Post a Comment for "Combine Nested For Loops In Python"