<br><br><div class="gmail_quote">On 6 August 2012 16:52, Tom P <span dir="ltr"><<a href="mailto:werotizy@freent.dd" target="_blank">werotizy@freent.dd</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
consider a nested loop algorithm -<br>
<br>
for i in range(100):<br>
for j in range(100):<br>
do_something(i,j)<br>
<br>
Now, suppose I don't want to use i = 0 and j = 0 as initial values, but some other values i = N and j = M, and I want to iterate through all 10,000 values in sequence - is there a neat python-like way to this? I realize I can do things like use a variable for k in range(10000): and then derive values for i and j from k, but I'm wondering if there's something less clunky.<span class="HOEnZb"><font color="#888888"><br>
-- <br>
<a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/<u></u>mailman/listinfo/python-list</a><br>
</font></span></blockquote></div><br><div><div>Are you familiar with the itertools module?</div><div><br></div><div>itertools.product is designed for this purpose:</div><div><a href="http://docs.python.org/library/itertools#itertools.product">http://docs.python.org/library/itertools#itertools.product</a></div>
</div>