On 23 December 2011 02:11, bruce <badoug...@gmail.com> wrote: > hi. > > got a test where i have multiple lists with key/values. trying to figure out > how to do a join/multiply, or whatever python calls it, where i have a > series of resulting lists/dicts that look like the following.. > > the number of lists/rows is dynamic.. > the size of the list/rows will also be dynamic as well. > > i've looked over the py docs, as well as different potential solns.. > > psuedo code, or pointers would be helpful. > > thanks... > > test data > a['a1']=['a1','a2','a3'] > a['a2']=['b1','b2','b3'] > a['a3']=['c1','c2','c3'] > > end test result:: > a1:a1,a2:b1,a3:c1 > a1:a2,a2:b1,a3:c1 > a1:a3,a2:b1,a3:c1 > > a1:a1,a2:b2,a3:c1 > a1:a2,a2:b2,a3:c1 > a1:a3,a2:b2,a3:c1 > > a1:a1,a2:b3,a3:c1 > a1:a2,a2:b3,a3:c1 > a1:a3,a2:b3,a3:c1 > > a1:a1,a2:b1,a3:c2 > a1:a2,a2:b1,a3:c2 > a1:a3,a2:b1,a3:c2 > > a1:a1,a2:b2,a3:c2 > a1:a2,a2:b2,a3:c2 > a1:a3,a2:b2,a3:c2 > > a1:a1,a2:b3,a3:c2 > a1:a2,a2:b3,a3:c2 > a1:a3,a2:b3,a3:c2 > > a1:a1,a2:b1,a3:c3 > a1:a2,a2:b1,a3:c3 > a1:a3,a2:b1,a3:c3 > > a1:a1,a2:b2,a3:c3 > a1:a2,a2:b2,a3:c3 > a1:a3,a2:b2,a3:c3 > > a1:a1,a2:b3,a3:c3 > a1:a2,a2:b3,a3:c3 > a1:a3,a2:b3,a3:c3 > > > > _______________________________________________ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor >
I think you want to take a look at the itertools module (http://docs.python.org/library/itertools.html), probably itertools.product, although I can't see exactly what you want as a final result. The process will be something like: turn a into list of lists of key:value pairs call itertools.product() using star notation (http://docs.python.org/tutorial/controlflow.html#unpacking-argument-lists) to turn the list into sequential arguments -- Rich "Roadie Rich" Lovely Just because you CAN do something, doesn't necessarily mean you SHOULD. In fact, more often than not, you probably SHOULDN'T. Especially if I suggested it. 10 re-discover BASIC 20 ??? 30 PRINT "Profit" 40 GOTO 10 _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor