Re: comple list slices
- From: William Meyer <wmmeyer@xxxxxxxxx>
- Date: Tue, 28 Feb 2006 18:04:48 +0000 (UTC)
<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?
.
- Follow-Ups:
- Re: comple list slices
- From: johnzenger
- Re: comple list slices
- References:
- comple list slices
- From: William Meyer
- Re: comple list slices
- From: johnzenger
- Re: comple list slices
- From: William Meyer
- Re: comple list slices
- From: johnzenger
- comple list slices
- Prev by Date: Re: PEP 354: Enumerations in Python
- Next by Date: Numerical solver
- Previous by thread: Re: comple list slices
- Next by thread: Re: comple list slices
- Index(es):
Relevant Pages
|