<johnzenger <at> gmail.com> writes: > Although I don't know if this is faster or more efficient than your > current solution, it does look cooler: > > def grouprows(inrows): > rows = [] > rows[:] = inrows # makes a copy because we're going to be > deleting > while len(rows) > 0: > rowspan = rows[0]["rowspan"] > yield rows[0:rowspan] # "returns" this value, but control flow > unaffected > del rows[0:rowspan] # remove what we just returned from the > list, and loop > > grouper = grouprows(copyrows) > print [x for x in grouper]
wow, i think this is much better then my solution. And you can easily call it for subgroups: grouper = grouprows(rows) for x in grouper grouperTwo = grouprows(x) for y in grouperTwo Do i need to copy the list in the iterator? (if I am not planning on using rows again) The reference count for the list members will get bumped on yield right? -- http://mail.python.org/mailman/listinfo/python-list