Kent thanks again for your input, rest assured is just the haste of my responses that goes unchecked :)
many thanks, Gonzalo. 2009/6/9 Kent Johnson <[email protected]>: > On Mon, Jun 8, 2009 at 12:56 PM, Gonzalo > Garcia-Perate<[email protected]> wrote: >> Kent, Emile thank you both. You're absolutely right, I was going for >> range because I thought it made the code more readable/more explicit. >> I hadn't taken into account the performance hit of creating the list >> and iterating through it. I'm not sure it was more readable either. >> >> the function now reads: >> def within_range_final(self, n, n2, threshold=5): >> return n2-threshold <= n <= n2+threshold+1 > > You probably don't want the +1. What should be the result of > self.within_range_final(7, 5, 1) > ? > > You might think a bit about testing your functions, since you have > posted several that don't do what you think they do. It's important to > test common cases, edge cases, and failure cases. For example you > might test all the combinations > 1, 5, 1 - far outlier > 3, 5, 1 - edge case > 4, 5, 1 - edge case > 5, 5, 1 - average case > 6, 5, 1 - edge case > 7, 5, 1 - edge case > 10, 5, 1 - far outlier > > Kent > _______________________________________________ Tutor maillist - [email protected] http://mail.python.org/mailman/listinfo/tutor
