<br><br><div><span class="gmail_quote">On 7/23/07, <b class="gmail_sendername">Bob Gailer</b> <<a href="mailto:bgailer@alum.rpi.edu">bgailer@alum.rpi.edu</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
A correction to the code at the end. The test of self.total_num_of_items<br>should precede the pop(0)</blockquote><div><br><div>
<br>
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:<br>
<br>
class Table_Creator(object):<br>
def __init__(self, total_num_of_items, max_num_of_items_per_row):<br>
self.given_items = range(total_num_of_items)<br>
self.max_num_of_items_per_row = max_num_of_items_per_row<br>
<br>
def create_grid(self):<br>
table = []<br>
while True:<br>
row = []<br>
while len(row) < self.max_num_of_items_per_row:<br>
if not self.given_items:<br>
if row:<br>
table.append(tuple(row))<br>
return table<br>
row.append(self.given_items.pop(0))<br>
table.append(tuple(row))<br>
</div> </div><br></div><br>