Why does the value of the variables in list change in Python?
<p>I don't understand this behavior of the Python 2.7.12...</p>

<p>Please verify the code, pasted below:</p>

<pre><code>test = [(('AAA_1', 'BBB_1', 'CCC_1'), 1), (('AAA_2', 'BBB_2', 'CCC_2'), 2),(('AAA_3', 'BBB_3', 'CCC_3'), 3), (('AAA_4', 'BBB_4', 'CCC_4'), 4)]
for i, j in enumerate(test):
    for k, l in enumerate(j[0]):
        if k == 0:
            dc['first'] = l
        elif k == 1:
            dc['second'] = l
        elif k == 2:
            dc['third'] = l
        elif k == 3:
            dc['fourth'] = l
    c.append(dc)
    print "/n"
    print "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXx"
    print dc
    print json.dumps(c, indent=1)
    print c

print json.dumps(c, indent=1)
</code></pre>

<p>Results of the code displayed above are stored in public pastebin: <a href="http://pastebin.com/GkrTyseg" rel="nofollow noreferrer">http://pastebin.com/GkrTyseg</a></p>

<p>What is strange for me:
By appending the list: c I would like to received the list of dictionaries. This dictionaries may represent the each type of AAA,BBB,CCC tuples. I used dictionaries to convert this into json to have easy way to use this data by webservices. </p>

<p>Anyway, I expected to receive the json:</p>

<pre><code> {
  "second": "BBB_1",
  "third": "CCC_1",
  "first": "AAA_1"
 },
 {
  "second": "BBB_2",
  "third": "CCC_2",
  "first": "AAA_2"
 },
 {
  "second": "BBB_3",
  "third": "CCC_3",
  "first": "AAA_3"
 },
 {
  "second": "BBB_4",
  "third": "CCC_4",
  "first": "AAA_4"
 }
</code></pre>

<p>But actual results are:</p>

<pre><code> {
  "second": "BBB_4",
  "third": "CCC_4",
  "first": "AAA_4"
 },
 {
  "second": "BBB_4",
  "third": "CCC_4",
  "first": "AAA_4"
 },
 {
  "second": "BBB_4",
  "third": "CCC_4",
  "first": "AAA_4"
 },
 {
  "second": "BBB_4",
  "third": "CCC_4",
  "first": "AAA_4"
 }
</code></pre>

<p>Why previously appended values changes their values to new ones?</p>

<p>The same results I recieived when I used instead of list: c additional dictionary, to get prettier json, than using list. But results were the same...
I tried using (instead of the list: c):</p>

<pre><code>main_dc[i+1] = dc 
</code></pre>

<p>How can I prevent to not change the values of the elements of the list or dictionary?</p>