Problem with algorithm

Charles Sanders C.delete_this.Sanders at BoM.GOv.AU
Fri Apr 13 02:31:39 EDT 2007


Paul Rubin wrote:
[snip]
> 
>     def a(n):
>         if n==0:
>             yield ''
>             return
>         for c in s:
>             for r in a(n-1):
>                 yield c+r
> 
>     print list(a(3))

Of course, obvious in retrospect, recursion instead of iteration.
I have yet to completely wean myself off Fortran style thinking.

Charles



More information about the Python-list mailing list