python loops

Michael.Coll-Barth at VerizonWireless.com Michael.Coll-Barth at VerizonWireless.com
Thu Aug 31 15:23:37 EDT 2006



> -----Original Message-----
> From: Kay Schluehr
> 
> >
> > python:
> > while i < length:
> > 			i += 1
> 
> As AlbaClause had demonstrated you can iterate over indices as well
> using the for-statement and the range() function. But you can also
> combine iterating over elements and indices at the same time using the
> builtin enumerate() type:
> 
> for i, item in enumerate(("s1","s2")):
>     print i,item
> 
> 0  s1
> 1  s2


Newbie here.

I thought the xrange was preferred?  for x in xrange(length):

But, I thought that was too obvious an answer and I was missing something.  I tried your code but it would not work.  Then I realized I was behind the times with python2.2  It works in, at least, python 2.4


The information contained in this message and any attachment may be
proprietary, confidential, and privileged or subject to the work
product doctrine and thus protected from disclosure.  If the reader
of this message is not the intended recipient, or an employee or
agent responsible for delivering this message to the intended
recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify me
immediately by replying to this message and deleting it and all
copies and backups thereof.  Thank you.




More information about the Python-list mailing list