Dictionary Combinations - Unequal Number of Keys & Values
<p>I want to print all unique combinations of keys and values for this dictionary:</p>

<pre><code>items = {'a':[10,100,1000],'b':[11,110],'c':[12,120]}
</code></pre>

<p>Using the code,</p>

<pre><code>for key, value in items.items():
    print(key,value)
</code></pre>

<p>I receive the following output:</p>

<pre><code>b [11, 110]
c [12, 120]
a [10, 100, 1000]
</code></pre>

<p>I would like to produce the following result given the dictionary:</p>

<pre><code>b 11
b 110
c 12
c 120
a 10
a 100
a 1000
</code></pre>

<p>Order of the key-value combinations is not important, but the result should preserve the relationship.  As always, any recommended resources and/or search terms associated with this problem will be appreciated.</p>

<p>Using <a href="https://docs.python.org/2/library/itertools.html#itertools.chain" rel="nofollow"><code>itertools.chain.from_iterables</code></a> and <a href="http://www.secnetix.de/olli/Python/list_comprehensions.hawk" rel="nofollow">list comprehension</a>, you can "flatten" this to a list of tuples:</p>

<pre><code>In [27]: import itertools

In [28]: list(itertools.chain.from_iterable([[(item_[0], v) for v in item_[1]] for item_ in items.items()]))
Out[28]: 
[('a', 10),
 ('a', 100),
 ('a', 1000),
 ('c', 12),
 ('c', 120),
 ('b', 11),
 ('b', 110)]
</code></pre>

<p>From this, it's easy to do anything you want like printing it:</p>

<pre><code>In [29]: for k, v in itertools.chain.from_iterable([[(item_[0], v)     for v in item_[1]] for item_ in items.items()]):
   ....:     print k, v
   ....:     
a 10
a 100
a 1000
c 12
c 120
b 11
b 110
</code></pre>

python loops dictionary