Q:

What's the best way to obtain all the combinations (Cartesian product) of lists?

Suppose I have the following. 
a = [[1,2,3],[4,5,6],[7,8,9]]
b = [['a','b'],['c','d'],['e','f']]

How do I obtain the following?
[1,2,3,'a','b']
[1,2,3,'c','d']
[1,2,3,'e','f']
[4,5,6,'a','b']
[4,5,6,'c','d']
[4,5,6,'e','f']
[7,8,9,'a','b']
[7,8,9,'c','d']
[7,8,9,'e','f']

A:

from itertools import product
a = [[1,2,3],[4,5,6],[7,8,9]]
b = [['a','b'],['c','d'],['e','f']]

print [x+y for (x,y) in product(a,b)]

A:

In [1]: from itertools import product

In [2]: a = [[1,2,3],[4,5,6],[7,8,9]]

In [3]: b = [['a','b'],['c','d'],['e','f']]

In [4]: map(lambda x: x[0]+x[1], product(a, b))
Out[4]: 
[[1, 2, 3, 'a', 'b'],
 [1, 2, 3, 'c', 'd'],
 [1, 2, 3, 'e', 'f'],
 [4, 5, 6, 'a', 'b'],
 [4, 5, 6, 'c', 'd'],
 [4, 5, 6, 'e', 'f'],
 [7, 8, 9, 'a', 'b'],
 [7, 8, 9, 'c', 'd'],
 [7, 8, 9, 'e', 'f']]

