simple recursion help

drs drs at remove-to-send-mail-ecpsoftware.com
Sat Oct 23 15:37:10 EDT 2004


Hi,  I am trying to find all lists of length x with elements a, b, and c.
To this end, I have created the class below, but it is not quite working and
I am having trouble figuring out what to change.  Does anyone have any
insight?

class c:
    def __init__(self):
        self.traits = 4 # number of list elements
        self.types = 3  # elements can be 0, 1, or 2

    def a(self):
        l = []
        for i in range(self.traits):
            l.append(self.b(str(i)))
        return l

    def b(self, s):
        if len(s) == self.types:
            return s
        for i in range(self.traits):
            return self.b(s + str(i))


i = c()
lst = i.a()


Thanks in advance,

-d





More information about the Python-list mailing list