*Naming Conventions*

Neil Cerutti horpner at yahoo.com
Tue Jun 5 09:00:15 EDT 2007


On 2007-06-04, Michael Hoffman <cam.ac.uk at mh391.invalid> wrote:
> Wildemar Wildenburger wrote:
>> While that is true, I guess it is commonplace to use i, j, k
>> and n (maybe others) in constructs like
>> 
>> for i in range(len(data)):
>>    do_stuff(data[i])
>> 
>> Or should the good python hacker do that differently? Hope not
>> ;).
>
> Well, yes, I would do:
>
> for item in data:
>     do_stuff(item)
>
> or, if using enumerate:
>
> for item_index, item in enumerate(data):
>     do_stuff(item_index, item)
>
> I agree with Bruno that i and j should be used only for
> indices, but I'm usually less terse than that.

I find i and j preferable to overly generic terms like "item."

-- 
Neil Cerutti



More information about the Python-list mailing list