<div dir="ltr"><div class="gmail_default" style="color:rgb(0,0,0)">Plenty to be going on with there ... thanks everyone!<br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On 18 November 2014 15:17, James Doig <span dir="ltr"><<a href="mailto:jamesdoig@gmail.com" target="_blank">jamesdoig@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"><div>Hi Doug, </div>Lists nested like this ( e.g: [1, [2, 3, [4 ,5 ,6 ,7]]] ) can be thought of as "tree" data structures.... Just incase you wanted to categorise the problem to aid future googling :)<div><br></div><div>Cheers,</div><div><br></div><div>James</div></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On 18 November 2014 12:56, Magnus Hagdorn <span dir="ltr"><<a href="mailto:magnus.hagdorn@marsupium.org" target="_blank">magnus.hagdorn@marsupium.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Doug,<br>
I think you will need to write an iterator which will return a tuple of indicies.<br>
<br>
How do you decide on the number of nested loops?<br>
<br>
Your program might looks something like<br>
<br>
def myIterator(some,args):<br>
  white some condition:<br>
      do some stuff to figure out what to do<br>
      yield (i,j,k,...)<br>
<br>
for indicies in myIterator(...):<br>
    do something with the tuple of indicies<br>
<br>
Hope this gives you a starting point<br>
<br>
Cheers<br>
magi<div><div><br>
<br>
<br>
On 18/11/14 12:08, Douglas Houston wrote:<br>
</div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div>
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<br>
nested 'for' loops. However, the number of loops (and therefore the<br>
depth of the nesting) cannot be predetermined.<br>
<br>
I've read that lots of nested loops are bad form anyway, and that "you<br>
should do it with functions instead".<br>
<br>
However I still can't work out how to set the number dynamically.<br>
<br>
<br>
for ((l=0; l<10; l++)); do<br>
​ ​<br>
  for ((m=0; m<10; m++))<br>
​;​<br>
do<br>
​ ​<br>
for (n=0; n<10; n++)); do<br>
​ ​<br>
something<br>
​ that uses l, m and n​<br>
<br>
     done<br>
   done<br>
done<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<br>
​ for nest_depth=4 (which in this case would use l, m, n and o)​, or any<br>
other number (which can't be predicted)?<br>
<br>
cheers,<br>
Doug<br>
<br>
PS I didn't write this in Python just for speed, but feel free to reply<br>
in Python if you want - the practice would be good for me.<br>
<br>
<br></div></div><span>
______________________________<u></u>_________________<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/<u></u>mailman/listinfo/edinburgh</a><br>
<br>
</span></blockquote><div><div>
<br>
______________________________<u></u>_________________<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/<u></u>mailman/listinfo/edinburgh</a><br>
</div></div></blockquote></div><br></div>
</div></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>