Do you know how to loop over cartesian products of two ranges in python, such as:
for i,j in cartesian(100,200):
print i, j
0,0
0,1
.
.
.
123,197
.
.
99,199
Do you know how to loop over cartesian products of two ranges in python, such as:
for i,j in cartesian(100,200):
print i, j
0,0
0,1
.
.
.
123,197
.
.
99,199
The product
function will work:
from itertools import product
for j in product(range(100), range(200)):
print j
Alternatively, from the product documentation:
Equivalent to nested for-loops in a generator expression. For example, product(A, B) returns the same as ((x,y) for x in A for y in B).
Maybe I'm missing something, but isn't it as simple as this:
for i in range(100):
for j in range(200):
print i, j
Slightly more optimized version:
inner_range = range(200)
for i in range(100):
for j in inner_range:
print i, j