Is using range() in for loops really Pythonic?

Grant Edwards grante at visi.com
Mon May 12 10:46:07 EDT 2008


On 2008-05-12, Ben Finney <bignose+hates-spam at benfinney.id.au> wrote:
> Paddy <paddy3118 at googlemail.com> writes:
>
>> I've used Fortran and C and so would tend to use either i,j,k as the
>> unused loop variable above, or, for clarity, call it something
>> descriptive like loop_count, if the loop body would be clearer.
>
> The problem with all of these names is that they also have long
> precedent as names of values that *will* be used inside the loop.

I guess people who standardize on loop_count never nest loops. :)

> Because of the precedent of those names, choosing one of those
> names doesn't make it clear to the reader that the value is
> never used; they have no indication from you of that until
> they look over the code a few times. It's implicit rather than
> explicit.

And when somebody adds a nested loop things fall apart.

-- 
Grant Edwards                   grante             Yow! BARBARA STANWYCK makes
                                  at               me nervous!!
                               visi.com            



More information about the Python-list mailing list