Python: Append a list to another list and Clear the first list
<p>So this just blew my mind. I am working on a python code where I create a list, append it to a master list and clear the first list to add some more elements to it. When I clear the first list, even the master list gets cleared. I worked on a lot of list appends and clears but never observed this.</p>

<pre><code>list1 = []
list2 = []
list1 = [1,2,3]
list2.append(list1)
list1
[1, 2, 3]
list2
[[1, 2, 3]]
del list1[:]
list1
[]
list2
[[]]
</code></pre>

<p>I know this happens with appending dictionaries but I did not know how to deal with lists. Can some one please elaborate?</p>

<p>I am using Python2.7</p>