Colors for Rows

Scott David Daniels Scott.Daniels at Acm.Org
Sun May 4 10:58:18 EDT 2008


D'Arcy J.M. Cain wrote:
> On Tue, 29 Apr 2008 15:03:23 -0400
> "J. Cliff Dyer" <jcd at sdf.lonestar.org> wrote:
>> Or, if you aren't sure how many colors you'll be using, try the more
>> robust:
>>
>> bg[z % len(bg)]
> 
> Good point although I would have calculated the length once at the
> start rather than each time through the loop.
> 
You may be surprised to find out that len(foo) is typically a
retrieval question, not so much a calculation.  Of course, measure
anything you care about, and special methods may do much more, but
in general, go for the simplest, clearest code you can write, and
then speed it up when it needs it.

I'd use len(bg) above unless my code was littered with calls to
len of the same thing, in which case it might it might be clearer
to choose a good name for len(bg).

--Scott David Daniels
Scott.Daniels at Acm.Org



More information about the Python-list mailing list