Re: comple list slices
- From: johnzenger@xxxxxxxxx
- Date: 28 Feb 2006 09:10:26 -0800
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]
This is basically just a simple function that rips chunks off the front
of a list and returns them. Because the function uses "yield" rather
than "return," it becomes a generator, which can be treated by Python
as an iterator.
.
- Follow-Ups:
- Re: comple list slices
- From: Felipe Almeida Lessa
- Re: comple list slices
- From: William Meyer
- Re: comple list slices
- References:
- comple list slices
- From: William Meyer
- Re: comple list slices
- From: johnzenger
- Re: comple list slices
- From: William Meyer
- comple list slices
- Prev by Date: Re: Best python module for Oracle, but portable to other RDBMSes
- Next by Date: Re: Is Python a Zen language?
- Previous by thread: Re: comple list slices
- Next by thread: Re: comple list slices
- Index(es):