Combinations of n Lists
Alex Martelli
aleaxit at yahoo.com
Thu Mar 1 10:37:29 EST 2001
"Tim Hochberg" <tim.hochberg at ieee.org> wrote in message
news:89bn6.1121$DY.186465 at news1.rdc1.az.home.com...
[snip]
> > def combinations(list1,list2):
> > return [ (i,j) for i in list1 for j in list2 ]
> >
> > print combinations( [1,2,3], ['a','b','c'] )
> >
> > [(1, 'a'), (1, 'b'), (1, 'c'), (2, 'a'), (2, 'b'), (2, 'c'), (3, 'a'),
(3,
[snip]
> zip([1,2,3], [4,5,6], [7,8,9], .... )
Nope -- this only gives [(1,4,7),(2,5,8),(3,6,9)], *not* all of the
other 24 requested combinations (1,4,8), (1,4,9), ..., (3,6,8).
Alex
More information about the Python-list
mailing list