Re: comple list slices



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.

.



Relevant Pages

  • Re: Just wondering
    ... If the task is to test the overhead, then the two loops need to be equivalent. ... compare map() time to for time, ... def doit: ... Doing the loop tells what it takes to loop. ...
    (comp.lang.python)
  • Re: Start and stop a ruby loop ;(
    ... def bar ... Because the object's instance variables of @baz and @quux haven't been ... it looks like you want to use a while loop instead of a for ... class MyFirstClass ...
    (comp.lang.ruby)
  • Re: Another TCPSocket Question
    ... require 'socket' ... puts "Entering loop" ... def initialize(tcp_sock) ... not shown here is required to deal with binary networking streams ...
    (comp.lang.ruby)
  • Re: Style question - defining immutable class data members
    ... The only difference between Case1 and Case2 classes is where the count ... on is discarded as you go through the next pass on the outer loop. ... def inc: ...
    (comp.lang.python)
  • Re: Style question - defining immutable class data members
    ... def inc: ... This is about a small optimization in defining ... Each one creates its own count, and a list variables, and manipulates them calls to inc and val. ... The values manipulated by one instance of C2 in one pass through the loop are not affected when, on the next pass through the loop, that instance is destroyed and another instance is created. ...
    (comp.lang.python)