Automatic increment

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Gheorghe Postelnicu

    #1

    Automatic increment

    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
  • thunderfoot@gmail.com

    #2
    Re: Automatic increment


    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(lineL ist):
    for itemCounter, item in enumerate(line. split()):
    myArray[counter, itemCounter]

    hth,
    Don

    Comment

    • John Machin

      #3
      Re: Automatic increment


      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.somel anguageothertha nPython ?

      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

      Comment

      Working...