Mapping Python list values to dictionary values
<p>I have a list of rows...</p>

<p><code>rows = [2, 21]</code></p>

<p>And a dictionary of data...</p>

<p><code>data = {'x': [46, 35], 'y': [20, 30]}</code></p>

<p>I'd like to construct a second dictionary, <code>dataRows</code>, keyed by the row that looks like this...</p>

<p><code>dataRows = {2: {'x': 46, 'y': 20}, 21: {'x': 35, 'y': 30}}</code></p>

<p>I tried the following code, but the values of <code>dataRows</code> are always the same (last value in loop):</p>

<pre><code>for i, row in enumerate(rows):
    for key, value in data.items():
        dataRows[row] = value[i]
</code></pre>

<p>Any assistance would be greatly appreciated.</p>

<p>Your issue is that you are not puting sub-dictionaries inside dataRows. The fix would be this:</p>

<pre><code>for i, row in enumerate(rows):
    dataRows[row] = {}
    for key, value in data.items():
        dataRows[row][key] = value[i]
</code></pre>

python