<div dir="ltr">Actually, Tom's use of itertools is more accurate than my patch-job :)</div><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature"><div dir="ltr">Andre Engelbrecht<br>Web Developer/Designer<br><a href="http://andre.engelbrechtonline.net" target="_blank">http://andre.engelbrechtonline.net</a><div><a href="http://www.tehnode.co.uk" target="_blank">http://www.tehnode.co.uk</a></div><div><br></div><div><span style="color:rgb(51,51,153);font-family:Ariel,Helvetica,'Sans Serif';font-size:12px;font-style:italic;line-height:15.296875px">Too brief? Here's why! <a href="http://emailcharter.org" target="_blank">http://emailcharter.org</a> </span><br></div></div></div></div>
<br><div class="gmail_quote">On Tue, Nov 18, 2014 at 1:07 PM, Tom Dalton <span dir="ltr"><<a href="mailto:tom.dalton@fanduel.com" target="_blank">tom.dalton@fanduel.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div><div><div>You can use itertools.product to simplify this even further. If the max-count for each loop is the same then you can do:<br><br></div><div>import itertools<br></div><div>N=3<br></div>for x in itertools.product(range(10), repeat=N):<br></div>    print x<br><br></div>If the max-count is different you can specify the range for each part separately:<br><br>for x in itertools.product(range(2), range(3), range(4)):<br>    print x<br><br></div>Ref <a href="https://docs.python.org/2/library/itertools.html#itertools.product" target="_blank">https://docs.python.org/2/library/itertools.html#itertools.product</a><br><br></div>Tom<br></div><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="h5">On 18 November 2014 13:04, Andre Engelbrecht <span dir="ltr"><<a href="mailto:litt.fire.sa@gmail.com" target="_blank">litt.fire.sa@gmail.com</a>></span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5"><div dir="ltr">Something like this maybe?<div><br></div><div><a href="https://gist.github.com/andrewebdev/e3a979cfb46380884f3a" target="_blank">https://gist.github.com/andrewebdev/e3a979cfb46380884f3a</a><br></div></div><div class="gmail_extra"><br clear="all"><div><div><div dir="ltr">Andre Engelbrecht<br>Web Developer/Designer<br><a href="http://andre.engelbrechtonline.net" target="_blank">http://andre.engelbrechtonline.net</a><div><a href="http://www.tehnode.co.uk" target="_blank">http://www.tehnode.co.uk</a></div><div><br></div><div><span style="color:rgb(51,51,153);font-family:Ariel,Helvetica,'Sans Serif';font-size:12px;font-style:italic;line-height:15.296875px">Too brief? Here's why! <a href="http://emailcharter.org" target="_blank">http://emailcharter.org</a> </span><br></div></div></div></div><div><div>
<br><div class="gmail_quote">On Tue, Nov 18, 2014 at 12:56 PM, Kenny Erasmuson <span dir="ltr"><<a href="mailto:kennyerasmuson@gmail.com" target="_blank">kennyerasmuson@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">It sounds like some kind of recursive function may be needed here. However, it also looks like the 'inner' most function call will then be operating on a variable number of parameters (e.g. l, m and n in your example, but it could be l, m, n, k, z, etc). Is that right?</div><div class="gmail_extra"><br><div class="gmail_quote"><div><div>On 18 November 2014 12:53, Tom Dalton <span dir="ltr"><<a href="mailto:tom.dalton@fanduel.com" target="_blank">tom.dalton@fanduel.com</a>></span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div><div dir="ltr"><div>Hey Doug,<br><br>There are a few ways you could do this, but it would be helpful if you could give a little more context on where you get l,m and n from and where the limit (10) comes from for each (or how it's determined). Also, what does the thing that uses those variables look like? Is it separate function calls, or a function that takes a list of arguments, or something else?<br><br></div><div>Cheers,<br><br></div>Tom<br></div><div class="gmail_extra"><br><div class="gmail_quote"><div><div>On 18 November 2014 12:08, Douglas Houston <span dir="ltr"><<a href="mailto:douglasrhouston@googlemail.com" target="_blank">douglasrhouston@googlemail.com</a>></span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div><div dir="ltr">Hi all,<br><br>I'm a bit stuck with this so maybe someone can help me.<br><br>I'm writing a little program that needs to iterate through several nested 'for' loops. However, the number of loops (and therefore the depth of the nesting) cannot be predetermined.<br><br>I've read that lots of nested loops are bad form anyway, and that "you should do it with functions instead".<br><br>However I still can't work out how to set the number dynamically.<br><br><br><span style="font-family:monospace">for ((l=0; l<10; l++)); do<br><div class="gmail_default" style="color:rgb(0,0,0);display:inline">​ ​</div> for ((m=0; m<10; m++))<div class="gmail_default" style="color:rgb(0,0,0);display:inline">​;​</div> do<br>   <div class="gmail_default" style="color:rgb(0,0,0);display:inline">​ ​</div>for (n=0; n<10; n++)); do<br>     <div class="gmail_default" style="color:rgb(0,0,0);display:inline">​ ​</div>something<div class="gmail_default" style="color:rgb(0,0,0);display:inline">​ that uses l, m and n​</div><br>    done<br>  done<br>done</span><br><br>So this is what it needs to look like if nest_depth=3<br><br>But how do I write a program that iterates something<div class="gmail_default" style="color:rgb(0,0,0);display:inline">​ for nest_depth=4 (which in this case would use l, m, n and o)​, or any other number (which can't be predicted)?<br></div><br>cheers,<br>Doug<br><br>PS I didn't write this in Python just for speed, but feel free to reply in Python if you want - the practice would be good for me.<br></div>
<br></div></div>_______________________________________________<br>
Edinburgh mailing list<br>
<a href="mailto:Edinburgh@python.org" target="_blank">Edinburgh@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/edinburgh" target="_blank">https://mail.python.org/mailman/listinfo/edinburgh</a><br>
<br></blockquote></div><br></div>
<br></div></div>_______________________________________________<br>
Edinburgh mailing list<br>
<a href="mailto:Edinburgh@python.org" target="_blank">Edinburgh@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/edinburgh" target="_blank">https://mail.python.org/mailman/listinfo/edinburgh</a><br>
<br></blockquote></div><br></div>
<br>_______________________________________________<br>
Edinburgh mailing list<br>
<a href="mailto:Edinburgh@python.org" target="_blank">Edinburgh@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/edinburgh" target="_blank">https://mail.python.org/mailman/listinfo/edinburgh</a><br>
<br></blockquote></div><br></div></div></div>
<br></div></div>_______________________________________________<br>
Edinburgh mailing list<br>
<a href="mailto:Edinburgh@python.org" target="_blank">Edinburgh@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/edinburgh" target="_blank">https://mail.python.org/mailman/listinfo/edinburgh</a><br>
<br></blockquote></div><br></div>
<br>_______________________________________________<br>
Edinburgh mailing list<br>
<a href="mailto:Edinburgh@python.org">Edinburgh@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/edinburgh" target="_blank">https://mail.python.org/mailman/listinfo/edinburgh</a><br>
<br></blockquote></div><br></div>