[Tutor] combinations

Magnus Lyckå magnus@thinkware.se
Sat May 10 20:05:02 2003


That's cute!

At 16:54 2003-05-10 -0600, Bob Gailer wrote:
>def tree(txt, result=''):
>   if txt:
>     for i in range(len(txt)):
>       foo(txt[:i] + txt[i+1:], result + txt[i])

I guess that should be "tree", not "foo"...

>   else:
>     print result

I was thinking...is there any simple iterative (not recursive)
solution for this in the general case where we don't have a
certain length of the string?

Not that recursion is bad in this case, I'm just curious if
people see a simple way to do this without recursion.


--
Magnus Lycka (It's really Lyckå), magnus@thinkware.se
Thinkware AB, Sweden, www.thinkware.se
I code Python ~ The shortest path from thought to working program