[Tutor] Iterating over multiple lists- options
Tony Cappellini
tony at tcapp.com
Mon Feb 7 10:03:08 CET 2005
I'm trying to generate an HTML table, from multiple lists.
There are 4 lists total, each of which *may* have a different length from
the other lists.
Each list has been stored in a master dictionary.
North=[Bill, Bob, Sue, Mary]
South=['Tim', ''Tom', 'Jim', 'John', 'Carl', 'Evan', 'Rich']
etc
d1={'North':North, 'South':South, 'East':East, 'West':West]
I want to iterate over all the lists a the same time, so I can populate an
html table.
This is approximately what the HTML table should look like, but the lists
can be in any order, top to bottom, and left to right.
South North East West
Tim Bill May Ellen
Tom Bob Mick
Jim Sue Ron
John Mary Keith
Carl Joey
Evan
Rich
Looking through my books on Python I've found examples for zip() and map()
both of which have serious shortcomings
That being, both of these functions can truncate the data, depending on
certain conditions
When iterating over multiple lists, it is fine if the mechanism returns an
empty string , or None for a non-existing list item.
I just wont display anything in the HTML table for missing items.
I know how to create the HTML table, statically. The problem is being able
to fill the table in one pass (preferably), which means my program would
need to iterate over
more than one list at the same time.
Even using the range to generate an index has different effects, depending
on the order in which the lists are referenced in the for loop.
Are there any other options available for iterating over multiple lists ?
More information about the Tutor
mailing list