On Wed, Nov 30, 2011 at 3:34 PM, Norman Khine <nor...@khine.net> wrote:
> hello, > > is there a better way to organise this code or optimise it. > > http://pastie.org/2944797 > > After glancing at it the only change that I would recommend (possibly) making is lines 58 and 39 - you can wrap the dictionaries (line line 7) and that will bring all your lines < 80 characters. Other than that it looks perfectly readable. You could add some docstrings for completeness. As far as anything else - is this code too slow? If not, why bother trying to optimise it? Obviously if you were doing something horribly inefficient like a bubble sort (especially considering Python has a built-in sort), then you would want to get rid of that, but I didn't really notice anything. Though now that I took a few more seconds, it does look like you're not using rows, aside from looping over it. If you only care about the values and not the collection as a whole you could (and should) change the list comprehension to a generator expression: >>> [x for x in (1,2,3)] [1, 2, 3] >>> (x for x in (1,2,3)) <generator object <genexpr> at 0x01BFB6C0> If you're not familiar with a generators, I highly recommend this set of slides: http://www.dabeaz.com/generators/Generators.pdf HTH, Wayne
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor