Hi,
I have a list of rows which contains a list of cells (from a html table), and I
want to create an array of logical row groups (ie group rows by the rowspan). I
am only concerned with checking the rowspan of specific columns, so that makes
it easier, but I am having trouble implementing it in
A couple questions:
1- what is j?
2- what does the rows[x][y] object look like? I assume it's a dict
that has a rowspan key. Can rows[x][y][rowspan] sometimes be 0?
Perhaps you're looking for something like this:
rowgroups = []
rowspan = 0
for i in range( len(rows) ):
if rowspan = 0:
Python lets you iterate through a list using an integer index, too,
although if you do so we will make fun of you. You can accomplish it
with a while loop, as in:
i = 0
while i len(rows):
if rows[i] == This code looks like BASIC without the WEND, doesn't
it?:
rowgroups.append(Pretty
shandy.b at gmail.com writes:
A couple questions:
1- what is j?
2- what does the rows[x][y] object look like? I assume it's a dict
that has a rowspan key. Can rows[x][y][rowspan] sometimes be 0?
Perhaps you're looking for something like this:
rowgroups = []
rowspan = 0
for i in
johnzenger at gmail.com writes:
Python lets you iterate through a list using an integer index, too,
although if you do so we will make fun of you. You can accomplish it
with a while loop, as in:
i = 0
while i len(rows):
if rows[i] == This code looks like BASIC without the WEND,
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
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:
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):
Em Ter, 2006-02-28 às 09:10 -0800, [EMAIL PROTECTED] escreveu:
Although I don't know if this is faster or more efficient than your
current solution, it does look cooler:
[snip]
print [x for x in grouper]
This is not cool. Do
print list(grouper)
--
Quem excele em empregar a força militar
[EMAIL PROTECTED]:
Len(rows) recalculates each time the while loop begins. Now that I
think of it, rows != [] is faster than len(rows) 0.
the difference is very small, and len(rows) is faster than rows != []
(the latter creates a new list for each test).
and as usual, using the correct
10 matches
Mail list logo