Do you know how to loop over cartesian products of 100 and 200 in python, such as:
for cartesian(100,200):
print result
1,1
1,2
.
.
.
123,197
.
.
100,200
Do you know how to loop over cartesian products of 100 and 200 in python, such as:
for cartesian(100,200):
print result
1,1
1,2
.
.
.
123,197
.
.
100,200
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