Get the cartesian product of a series of lists in Python
<p>How can I get the Cartesian product (every possible combination of values) from a group of lists?</p>

<p>Input: </p>

<pre><code>somelists = [
   [1, 2, 3],
   ['a', 'b'],
   [4, 5]
]
</code></pre>

<p>Desired output:</p>

<pre><code>[(1, 'a', 4), (1, 'a', 5), (1, 'b', 4), (1, 'b', 5), (2, 'a', 4), (2, 'a', 5) ...]
</code></pre>
