On 7/23/07, Bob Gailer <[EMAIL PROTECTED]> wrote:
>
> A correction to the code at the end. The test of self.total_num_of_items
> should precede the pop(0)



Bob, I spent today studying what you've been telling me and I put the
finishing touches to make your code pass my battery of tests.  It still is
repetitive, i.e., table.append(tuple(row)), but I've found guidance in what
Alan had to say about code readability and easy maintenance, and am no
longer going to press the matter:

class Table_Creator(object):
    def __init__(self, total_num_of_items, max_num_of_items_per_row):
        self.given_items = range(total_num_of_items)
        self.max_num_of_items_per_row = max_num_of_items_per_row

    def create_grid(self):
        table = []
        while True:
            row = []
            while len(row) < self.max_num_of_items_per_row:
                if not self.given_items:
                    if row:
                        table.append(tuple(row))
                    return table
                row.append(self.given_items.pop(0))
            table.append(tuple(row))
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to