Combinations of n Lists

Sean 'Shaleh' Perry shaleh at valinux.com
Wed Feb 28 11:20:41 EST 2001


On 28-Feb-2001 Warren Postma wrote:
> I was just wondering if anyone has a more general version of this little
> helper function:
> 
> 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,
> 'b'), (3, 'c')]
> 

try zip() in python2 (-:




More information about the Python-list mailing list