comple list slices
johnzenger at gmail.com
johnzenger at gmail.com
Tue Feb 28 15:29:27 EST 2006
You don't need to copy the list; but if you don't, your original list
will be emptied.
Len(rows) recalculates each time the while loop begins. Now that I
think of it, "rows != []" is faster than "len(rows) > 0."
By the way, you can also do this using (gasp) a control index:
def grouprows(rows):
index = 0
while len(rows) > index:
rowspan = rows[index]["rowspan"]
yield rows[index:rowspan + index]
index += rowspan
...which kind of brings us back to where we started.
More information about the Python-list
mailing list