By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,427 Members | 1,378 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,427 IT Pros & Developers. It's quick & easy.

Automatic increment

P: n/a
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?

Thanks,
--
Gheorghe Postelnicu, PhD
MGH, Harvard Medical School
Nov 30 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a

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

Nov 30 '06 #2

P: n/a

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

Nov 30 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.