Charles Sanders <[EMAIL PROTECTED]> writes:
> Forgive any silly mistakes I have made (I've been teaching
> myself python for about 1 week) but there is a moderately
> well known algorithm for this that extends to arbitrary
> lengths of both the list of alternatives and the length
> of the required output, and avoids deeply nested loops.

    s = "abcd"

    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))
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to