Splice dictonary to create list of tuples in Python
<p>So I have these two dictonaries, where the key is a year (an integer), and the value a float. I want to combine these two, and as a result create a list of tuples, with the year, value1, value2. So like this:</p>

<p>Dictonary 1</p>

<pre><code> {2011: 1.0,
 2012: 2.0,
 2013: 3.0}
</code></pre>

<p>Dictonary 2</p>

<pre><code> {2011: 4.0,
 2012: 5.0,
 2013: 6.0}
</code></pre>

<p>Prefered result:</p>

<pre><code> [(2011, 1.0, 4.0),
 (2012, 2.0, 5.0),
 (2013, 3.0, 6.0)]
</code></pre>

<p>Is there an easy way of doing this? Thank for your help!</p>

<p>If both dictionaries have the same keys:</p>

<pre><code>[(k, dict1[k], dict2[k]) for k in dict1.keys()]
</code></pre>

<p>Example:</p>

<pre><code>In[33]: dict1 =  {2011: 1.0,
 2012: 2.0,
 2013: 3.0}
In[34]: dict2 =  {2011: 4.0,
 2012: 5.0,
 2013: 6.0}
In[35]: [(k, dict1[k], dict2[k]) for k in dict1.keys()]
Out[35]: [(2011, 1.0, 4.0), (2012, 2.0, 5.0), (2013, 3.0, 6.0)]
</code></pre>

python python-2.7