Python Cartesian Product
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/533905/get-the-cartesian-product-of-a-series-of-lists-in-python">Get the cartesian product of a series of lists in Python</a>  </p>
</blockquote>



<p>I'm trying to figure out some logic that I just can't wrap my head around. Say I have the following data structure:</p>

<pre><code>letters = (
    ('b','c'),
    ('a','e','ee'),
    ('d','f'),
    ('e','y'),
)
</code></pre>

<p>How would I iterate through this to get every possible string combination:</p>

<pre><code>bade
cade
bede
cede
beede
ceede
bafe
cafe
befe
cefe
beefe
ceefe
bady
cady
bedy
cedy
beedy
ceedy
bafy
cafy
befy
cefy
beefy
ceefy
</code></pre>
