Automatic increment

thunderfoot at gmail.com thunderfoot at gmail.com
Thu Nov 30 19:21:51 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]
>         itemCounter = itemCounter + 1
>     counter = counter +1
>
> Is there a way to get rid of the manual incrementation of the 2 counters?
>

for counter, line in enumerate(lineList):
    for itemCounter, item in enumerate(line.split()):
        myArray[counter, itemCounter]

hth,
Don




More information about the Python-list mailing list