Re: [Tutor] variable numbers of for loops

2010-11-23 Thread Jose Amoreira
On Tuesday, November 23, 2010 02:01:40 pm Mac Ryan wrote: > The code you wrote generates programs like: > > for l0 in alphabet: > for l1 in alphabet: > for l2 in alphabet: > word = "".join([eval("l"+str(i)) for i in range(n)]) > listOfWords.append(word) > > wh

Re: [Tutor] variable numbers of for loops

2010-11-23 Thread Alan Gauld
"Mac Ryan" wrote I am not 100% sure I got the terms of your problem and I am neither an official tutor of this list, so disregard my comment if it is irrelevant... If you are a member of the list and contribute you are an official tutor. There are no high priests here :-) Alan G. _

Re: [Tutor] variable numbers of for loops (also iteration/recursion)

2010-11-23 Thread Chris Fuller
You can always substitute Iteration for Recursion by making the stack an explicit part of your code. As an example, imagine you are traversing this directory tree: birds birds/owls birds/owls/snowy birds/owls/barn birds/owls/great-horned birds/eagles birds/eagles/golden birds/eagles/bald birds/e

Re: [Tutor] variable numbers of for loops

2010-11-23 Thread Mac Ryan
On Tue, 23 Nov 2010 13:16:46 + Jose Amoreira wrote: > I read somewhere that for any recursive algorithm there is a > sequential one that is equivalent > [...] > Is there a more straightforward way of solving my specific problem > or, better yet, a general solution to the need of a variable nu

Re: [Tutor] variable numbers of for loops

2010-11-23 Thread Andre Engels
On Tue, Nov 23, 2010 at 2:16 PM, Jose Amoreira wrote: > Is there a more straightforward way of solving my specific problem or, better > yet, a general solution to the need of a variable number of for loops? If you need a variable number of loops, put the loops themselves in a loop, which you go

[Tutor] variable numbers of for loops

2010-11-23 Thread Jose Amoreira
Hi, This is a somewhat algorithmic question, not strictly pythonic. I was writing a program to generate all possible n-letter words with letters taken from an alphabet (I mean, if the alphabet is ['a','b'] the one-letter words are 'a' and 'b', the two letter words are 'aa', 'ab', 'ba', 'bb' and