Automatic increment

John Machin sjmachin at lexicon.net
Thu Nov 30 19:42:13 CET 2006


Gheorghe Postelnicu wrote:
> Hi,
>
> I have a situation of the following type:
>
> for line in lineList:
>     for item in line.split()
>         myArray[counter, itemCounter]

What do you imagine that the above line is doing? Alternatively, should
you be posting in comp.lang.somelanguageotherthanPython ?


>         itemCounter = itemCounter + 1
>     counter = counter +1
>
> Is there a way to get rid of the manual incrementation of the 2 counters?

You could have saved some wear and tear on your pinkies by doing e.g.
itemCounter += 1

Cheers,
John




More information about the Python-list mailing list