comple list slices

2006-02-28 Thread William Meyer
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

Re: comple list slices

2006-02-28 Thread shandy . b
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:

Re: comple list slices

2006-02-28 Thread johnzenger
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

Re: comple list slices

2006-02-28 Thread William Meyer
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

Re: comple list slices

2006-02-28 Thread William Meyer
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,

Re: comple list slices

2006-02-28 Thread johnzenger
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

Re: comple list slices

2006-02-28 Thread William Meyer
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:

Re: comple list slices

2006-02-28 Thread johnzenger
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):

Re: comple list slices

2006-02-28 Thread Felipe Almeida Lessa
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

Re: comple list slices

2006-02-28 Thread Fredrik Lundh
[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