On 2 Nov, 22:03, Carsten Haese <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] wrote:
> > Anyway what I want to do is experiment with code similar to this (i.e.
> > same algorithm and keep the recursion) in other languages,
> > particularly vbscript and wondered what it would look like if it was
> > rewritten to NOT use the yield statement
>
> An obvious (though memory-inefficient) replacement is to accumulate a
> list and return the list. Initialize a result variable to an empty list,
> and instead of yielding elements, append them to the result variable.
> Then return the result variable at the end of the function.
>
> HTH,
>
> --
> Carsten Haesehttp://informixdb.sourceforge.net

That did it and I can still understand it!

def allperm(str):
  if len(str) <= 1:
     return str
  else:
     biglist = []
     for perm in allperm(str[1:]):
        for i in xrange(len(str)): #minor change here
           biglist.append(perm[:i] + str[0:1] + perm[i:])

  return biglist

for x in allperm("ABCD"):
   print x
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to