Get all pairs from elements in sublists
<p>I have a list of sublists. I need all possible pairs between the elements in the sublists. For example, for a list like this: </p>

<pre><code>a=[[1,2,3],[4,5],[6]]
</code></pre>

<p>The result should be: </p>

<pre><code>result=[[1,4], [1,5], [1,6], 
        [2,4], [2,5], [2,6], 
        [3,4], [3,5], [3,6], 
        [4,6], [5,6]]
</code></pre>

<p>The lists (and sublists) are of various, random lengths. </p>

<pre><code>from itertools import chain, product, combinations

sublists = [[1, 2, 3], [4, 5], [6]]
pairs = chain.from_iterable(
    product(*sublist_pair) for sublist_pair in combinations(sublists, 2)
)
for x, y in pairs:
    print(x, y)
</code></pre>

python