Re: [Tutor] don't repeat yourself; question about code optimization CORRECTION

2007-07-29 Thread tpc247
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

Re: [Tutor] don't repeat yourself; question about code optimization

2007-07-29 Thread tpc247
On 7/23/07, Alan Gauld [EMAIL PROTECTED] wrote: The prime directive of coding is make it readable! The DRY principle is just that a principle. If repeating makes for more maintainable or readable code then repeat yourself. Remember 80% of the cost of software is in maintenance not initial

Re: [Tutor] don't repeat yourself; question about code optimization CORRECTION

2007-07-29 Thread Eric Brunson
[EMAIL PROTECTED] wrote: On 7/23/07, *Bob Gailer* [EMAIL PROTECTED] mailto:[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

Re: [Tutor] don't repeat yourself; question about code optimization

2007-07-29 Thread ALAN GAULD
assert create_table(5, 3) == [(0, 1, 2), (3, 4)] AssertionError I know that my method of calculating the number of rows is faulty, but I'm not sure how to correct it. num_rows = (num_items/row_size) + (num_items%row_size) This uses integer division then adds the remainder, so for

Re: [Tutor] don't repeat yourself; question about code optimization CORRECTION

2007-07-29 Thread Bob Gailer
[EMAIL PROTECTED] wrote: On 7/23/07, *Bob Gailer* [EMAIL PROTECTED] mailto:[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

Re: [Tutor] don't repeat yourself; question about code optimization

2007-07-23 Thread tpc247
On 7/20/07, Bob Gailer [EMAIL PROTECTED] wrote: Take advantage of slicing: def create_grid(self): table = [] for i in range(0, len(self.total_num_of_items), self.max_num_of_items_per_row): table.append(tuple(self.total_num_of_items[i : i +

Re: [Tutor] don't repeat yourself; question about code optimization

2007-07-23 Thread Alan Gauld
[EMAIL PROTECTED] wrote one part where I believe I violate the prime directive of coding, which is not to repeat yourself: The prime directive of coding is make it readable! The DRY principle is just that a principle. If repeating makes for more maintainable or readable code then repeat

Re: [Tutor] don't repeat yourself; question about code optimization

2007-07-23 Thread Bob Gailer
[EMAIL PROTECTED] wrote: On 7/20/07, *Bob Gailer* [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] wrote: Take advantage of slicing: def create_grid(self): table = [] for i in range(0, len( self.total_num_of_items), self.max_num_of_items_per_row):

Re: [Tutor] don't repeat yourself; question about code optimization CORRECTION

2007-07-23 Thread Bob Gailer
A correction to the code at the end. The test of self.total_num_of_items should precede the pop(0) [EMAIL PROTECTED] wrote: On 7/20/07, *Bob Gailer* [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] wrote: Take advantage of slicing: def create_grid(self): table = []

[Tutor] don't repeat yourself; question about code optimization

2007-07-20 Thread tpc247
dear fellow Python enthusiasts: in the last year I have been experimenting with Python, and I set out to create a function that, given a number of items and a maximum number of items per row, would generate a table of rows of items. However, there is one part where I believe I violate the prime

Re: [Tutor] don't repeat yourself; question about code optimization

2007-07-20 Thread Bob Gailer
[EMAIL PROTECTED] wrote: dear fellow Python enthusiasts: in the last year I have been experimenting with Python, and I set out to create a function that, given a number of items and a maximum number of items per row, would generate a table of rows of items. However, there is one part

Re: [Tutor] don't repeat yourself; question about code optimization

2007-07-20 Thread Bob Gailer
[EMAIL PROTECTED] wrote: dear fellow Python enthusiasts: in the last year I have been experimenting with Python, and I set out to create a function that, given a number of items and a maximum number of items per row, would generate a table of rows of items. However, there is one part

Re: [Tutor] don't repeat yourself; question about code optimization

2007-07-20 Thread Bob Gailer
[EMAIL PROTECTED] wrote: dear fellow Python enthusiasts: in the last year I have been experimenting with Python, and I set out to create a function that, given a number of items and a maximum number of items per row, would generate a table of rows of items. However, there is one part