On Wed, Jan 08, 2003 at 09:22:09AM -0700, Mike Doanh Tran wrote:
I have two list from my input form:
ListA: [a,b,c,d] ListB: [1,2,3,4]
How can i strip ListA and ListB so that the first value of ListA will correspond to the first value of ListB and the second of A to sencond of B and so on:
Example: (a,1), (b,2),(c,3),(d,4)
The python built-in function zip does this. ListC = zip(ListA, ListB) Unfortunately, zip seems to be disallowed in through-the-web zope code. weird. So you can roll your own: ListC = [] for i in range(min(len(ListA), len(ListB))): ListC.append( (ListA[i], ListB[i])) The call to min() ensures that ListC is only as long as the shortest of ListA and ListB so you don't get an IndexError by trying to access non-existent elements of the shorter list. not sure if that's what you want. -- Paul Winkler http://www.slinkp.com Look! Up in the sky! It's MEAT- MOLE RAT! (courtesy of isometric.spaceninja.com)