loop iterators?

Discussion in 'Python' started by SpreadTooThin, Oct 17, 2006.

  1. Hi I need to get a for loop to give me an element from a list and an
    index number...
    for example:

    i = 0
    l = ['a','b','c']
    for e in l:
    print l, i
    i = i + 1

    Is there a way to get rid of the i processing in this script?
    Sorry I'm still trying to learn python tricks here...
     
    SpreadTooThin, Oct 17, 2006
    #1
    1. Advertising

  2. In <>, SpreadTooThin
    wrote:

    > Hi I need to get a for loop to give me an element from a list and an
    > index number...
    > for example:
    >
    > i = 0
    > l = ['a','b','c']
    > for e in l:
    > print l, i
    > i = i + 1
    >
    > Is there a way to get rid of the i processing in this script?


    for i, e in enumerate(l):
    print i, e

    Ciao,
    Marc 'BlackJack' Rintsch
     
    Marc 'BlackJack' Rintsch, Oct 17, 2006
    #2
    1. Advertising

  3. SpreadTooThin

    Tim Chase Guest

    > l = ['a','b','c']
    > for e in l:
    > print l, i
    > i = i + 1
    >
    > Is there a way to get rid of the i processing in this script?
    > Sorry I'm still trying to learn python tricks here...



    for i, e in enumerate(l):
    print l, i

    -tkc
     
    Tim Chase, Oct 17, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Marcin Kaliciñski

    Iterators and reverse iterators

    Marcin Kaliciñski, May 8, 2005, in forum: C++
    Replies:
    1
    Views:
    490
    Kai-Uwe Bux
    May 8, 2005
  2. Daniel Pitts
    Replies:
    14
    Views:
    1,241
    Patricia Shanahan
    Dec 23, 2006
  3. , India
    Replies:
    10
    Views:
    1,084
    James Kanze
    Aug 8, 2009
  4. Single Stage to Orbit

    Using auto iterators in loop

    Single Stage to Orbit, Aug 4, 2012, in forum: C++
    Replies:
    5
    Views:
    434
    Single Stage to Orbit
    Aug 4, 2012
  5. Isaac Won
    Replies:
    9
    Views:
    387
    Ulrich Eckhardt
    Mar 4, 2013
Loading...

Share This Page