Appending object to a dictionary by key is replicating over the whole dictionary
<p>I have been trying to create a dictionary consisting of pairs of keys and an array of tuples. Each "instrument" within the "subportfolio" would be one of such tuples, and my idea is to populate a dictionary based on one of the tuple fields containing the key for the dictionary. The code below shows my current implementation:</p>

<pre><code>def assetClassBreakdown(subclasses, subportfolio):
    instrumentsDictionary = dict.fromkeys(subclasses, [])

    for instrument in subportfolio:
        # The subclass is in the ninth index within the instrument
        instrumentsDictionary[instrument[8]].append(instrument)

    return instrumentsDictionary
</code></pre>

<p>The problem is that every time I append a tuple based on the key (instrument[8]), it is appending this tuple to every key inside the dictionary. Basiclly, for every key I end up with exactly the same array of tuples. </p>