For copying a list: shallow_copy_of_list = old_list[:].
For copying a dict: shallow_copy_of_dict = dict(old_dict).
But for a
Besides the type(x)(x) hack, you can import copy module to make either shallow copy or deep copy:
In [29]: d={1: [2,3]}
In [30]: sd=copy.copy(d)
...: sd[1][0]=321
...: print d
{1: [321, 3]}
In [31]: dd=copy.deepcopy(d)
...: dd[1][0]=987
...: print dd, d
{1: [987, 3]} {1: [321, 3]}
From the docstring:
Definition: copy.copy(x)
Docstring:
Shallow copy operation on arbitrary Python objects.