Re: comple list slices
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.python archive

Re: comple list slices

From: <johnzenger@gmail.com>
Date: Tue Feb 28 2006 - 17:13:20 CET

Python lets you iterate through a list using an integer index, too,
although if you do so we will make fun of you. You can accomplish it
with a while loop, as in:

i = 0
while i < len(rows):
   if rows[i] == "This code looks like BASIC without the WEND, doesn't
it?":
      rowgroups.append("Pretty much.")
   i += 1 # or i += rowspan, whatever.

Do not try to do this with a for loop. In Python, "for i in xrange(5)"
is more like a "foreach $i ( {0,1,2,3,4,5})" in Perl, so changing i in
the loop will not change the value of i on the next loop iteration.
Received on Sun Apr 30 10:29:18 2006