I have a strange problem with list.append()
. I build a list joining some values from a dict, as follows:
In [3]: myDict = {'k1': u'value1', 'k2': [u'value2']}
In [4]: myList = myDict['k2']
In [5]: myList
Out[5]: [u'value2']
In [6]: myList.append(myDict['k1'])
In [7]: myList
Out[7]: [u'value2', u'value1']
In [8]: myDict
Out[8]: {'k1': u'value1', 'k2': [u'value2', u'value1']}
I don't understand the reason why myDict
is modified after append
in In [6]
(see the difference between In [2]
and Out [8]
).