Re: Simple python iteration question

2007-08-15 Thread Cameron Laird
In article <[EMAIL PROTECTED]>, BartlebyScrivener <[EMAIL PROTECTED]> wrote: >On Aug 14, 11:59 am, "Shawn Milochik" <[EMAIL PROTECTED]> wrote: > >> Just for my own sanity: Isn't this the third response advocating the >> use of enumerate()? Did the other responses not get through, or was >> this a

Re: Simple python iteration question

2007-08-15 Thread Roel Schroeven
Dennis Lee Bieber schreef: > On Wed, 15 Aug 2007 13:39:57 -0300, "Gabriel Genellina" > <[EMAIL PROTECTED]> declaimed the following in comp.lang.python: > >> "Never underestimate the bandwidth of a station wagon full of tapes >> hurtling down the highway" >> (Andrew S. Tanenbaum, Computer Network

Re: Simple python iteration question

2007-08-15 Thread Gabriel Genellina
En Wed, 15 Aug 2007 10:37:16 -0300, Cameron Laird <[EMAIL PROTECTED]> escribi�: > Shawn Milochik <[EMAIL PROTECTED]> wrote: >> Just for my own sanity: Isn't this the third response advocating the >> use of enumerate()? Did the other responses not get through, or was >> this a time-delay thing? >

Re: Simple python iteration question

2007-08-15 Thread BartlebyScrivener
On Aug 14, 11:59 am, "Shawn Milochik" <[EMAIL PROTECTED]> wrote: > Just for my own sanity: Isn't this the third response advocating the > use of enumerate()? Did the other responses not get through, or was > this a time-delay thing? > > Thanks, > Shawn Look at the timestamps. All within ten minu

Re: Simple python iteration question

2007-08-15 Thread Cameron Laird
In article <[EMAIL PROTECTED]>, Shawn Milochik <[EMAIL PROTECTED]> wrote: . . . >Just for my own sanity: Isn't this the third response advocating the >use of enumerate()? Did the other responses not get through, or was >this a

Re: Simple python iteration question

2007-08-14 Thread Shawn Milochik
> Use the enumerate() builtin. > > >>> l = ['a', 'b', 'c'] > >>> for i, v in enumerate(l): > ... print i, v > ... > 0 a > 1 b > 2 c > > -- Just for my own sanity: Isn't this the third response advocating the use of enumerate()? Did the other responses not get thro

Re: Simple python iteration question

2007-08-14 Thread Shawn Milochik
> this will get index and item at index, > > for i in range(0, len(l)): > print i > print l[i] > > > -- > http://mail.python.org/mailman/listinfo/python-list > Enumerate is better here -- it provides the same result and that's what it's for. However, if you do use range, the zero is unne

Re: Simple python iteration question

2007-08-14 Thread i3dmaster
or use its builtin enumerate function: for i, j in enumerate(list): print i, j --Jim On Aug 14, 2007, at 9:26 AM, [EMAIL PROTECTED] wrote: > On Aug 14, 10:22 am, Bryan <[EMAIL PROTECTED]> wrote: >> Hi, >> >> I just started with python, and have a for loop question >> >> In c++ (or a number

Re: Simple python iteration question

2007-08-14 Thread Shawn Milochik
On 8/14/07, Bryan <[EMAIL PROTECTED]> wrote: > Hi, > > I just started with python, and have a for loop question > > In c++ (or a number of other languages) I can do this: > > for (int i=0, j=0; i < i_len, j< j_len; ++i, ++j) {} > > If I have this in python: > l = ['a', 'b', 'c'] > > I want to get t

Re: Simple python iteration question

2007-08-14 Thread [EMAIL PROTECTED]
On Aug 14, 11:27 am, [EMAIL PROTECTED] (Lawrence Oluyede) wrote: > Bryan <[EMAIL PROTECTED]> wrote: > > How do I do this? > > for i, item in enumerate(l): > print i, item > ^^ That is the `most-correct` answer. But because you're new, I'll take this time to introduce you to help(), just in ca

Re: Simple python iteration question

2007-08-14 Thread Will Maier
On Tue, Aug 14, 2007 at 12:22:04PM -0400, Bryan wrote: > I just started with python, and have a for loop question > > In c++ (or a number of other languages) I can do this: > > for (int i=0, j=0; i < i_len, j< j_len; ++i, ++j) {} > > If I have this in python: > l = ['a', 'b', 'c'] > > I want to

Re: Simple python iteration question

2007-08-14 Thread Lawrence Oluyede
Bryan <[EMAIL PROTECTED]> wrote: > How do I do this? for i, item in enumerate(l): print i, item -- Lawrence, oluyede.org - neropercaso.it "It is difficult to get a man to understand something when his salary depends on not understanding it" - Upton Sinclair -- http://mail.python.org/mailm

Re: Simple python iteration question

2007-08-14 Thread [EMAIL PROTECTED]
On Aug 14, 10:22 am, Bryan <[EMAIL PROTECTED]> wrote: > Hi, > > I just started with python, and have a for loop question > > In c++ (or a number of other languages) I can do this: > > for (int i=0, j=0; i < i_len, j< j_len; ++i, ++j) {} > > If I have this in python: > l = ['a', 'b', 'c'] > > I want

Simple python iteration question

2007-08-14 Thread Bryan
Hi, I just started with python, and have a for loop question In c++ (or a number of other languages) I can do this: for (int i=0, j=0; i < i_len, j< j_len; ++i, ++j) {} If I have this in python: l = ['a', 'b', 'c'] I want to get the value and also an iterator: for i,v in len(l), l: pri