Hi; I have the following code: sql = 'create table if not exists categories (ID int(3) unsigned primary key, Category varchar(40), Parent varchar(40))' cursor.execute(sql) cursor.execute('select Category, Parent from categories;') data = cursor.fetchall() parents = [] Parents = [] for dat in data: if dat[1] not in parents: parents.append(dat[1]) Categories.append(dat[0]) Parents.append(dat[1]) Parents.sort() families = [] for parent in Parents: children = [] for dat in data: if dat[0] == parent: children.append(dat[1]) families.append([parent, children])
Now, what I want to do is to capture all nested categories, such that if x is the parent of y who is the parent of z, etc., I can print out the entire family tree. I'm at a loss as to how to do it! Please advise. TIA, Victor
-- http://mail.python.org/mailman/listinfo/python-list