Is using range() in for loops really Pythonic?

Ben Finney bignose+hates-spam at benfinney.id.au
Mon May 12 03:42:52 EDT 2008


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.

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.

-- 
 \     "As I bit into the nectarine, it had a crisp juiciness about it |
  `\          that was very pleasurable - until I realized it wasn't a |
_o__)            nectarine at all, but A HUMAN HEAD!!"  -- Jack Handey |
Ben Finney



More information about the Python-list mailing list