title: Python basic data references, list of same reference
body: <p>Say I have two lists:</p>
  
  <pre><code>&gt;&gt;&gt; l1=[1,2,3,4]
  &gt;&gt;&gt; l2=[11,12,13,14]
  </code></pre>
  
  <p>I can put those lists in a tuple, or dictionary, and it appears that they are all references back to the original list:</p>
  
  <pre><code>&gt;&gt;&gt; t=(l1,l2)
  &gt;&gt;&gt; d={'l1':l1, 'l2':l2}
  &gt;&gt;&gt; id(l1)==id(d['l1'])==id(t[0])
  True
  &gt;&gt;&gt; l1 is d['l1'] is t[0]
  True
  </code></pre>
  
  <p>Since they are references, I can change <code>l1</code> and the referred data in the tuple and dictionary change accordingly:</p>
  
  <pre><code>&gt;&gt;&gt; l1.append(5)
  &gt;&gt;&gt; l1
  [1, 2, 3, 4, 5]
  &gt;&gt;&gt; t
  ([1, 2, 3, 4, 5], [11, 12, 13, 14])
  &gt;&gt;&gt; d
  {'l2': [11, 12, 13, 14], 'l1': [1, 2, 3, 4, 5]}
  </code></pre>
  
  <p>Including if I append the reference in the dictionary <code>d</code> or mutable reference in the tuple <code>t</code>:</p>
  
  <pre><code>&gt;&gt;&gt; d['l1'].append(6)
  &gt;&gt;&gt; t[0].append(7)
  &gt;&gt;&gt; d
  {'l2': [11, 12, 13, 14], 'l1': [1, 2, 3, 4, 5, 6, 7]}
  &gt;&gt;&gt; l1
  [1, 2, 3, 4, 5, 6, 7]
  </code></pre>
  
  <p>If I now set <code>l1</code> to a new list, the reference count for the original list decreases:</p>
  
  <pre><code>&gt;&gt;&gt; sys.getrefcount(l1)
  4
  &gt;&gt;&gt; sys.getrefcount(t[0])
  4
  &gt;&gt;&gt; l1=['new','list']
  &gt;&gt;&gt; l1 is d['l1'] is t[0]
  False
  &gt;&gt;&gt; sys.getrefcount(l1)
  2
  &gt;&gt;&gt; sys.getrefcount(t[0])
  3
  </code></pre>
  
  <p>And appending or changing <code>l1</code> does not change <code>d['l1']</code> or <code>t[0]</code> since it now a new reference. The notion of indirect references is <a href="http://docs.python.org/reference/datamodel.html#objects">covered fairly well</a> in the Python documents but not completely. </p>
  
  <p>My questions:</p>
  
  <ol>
  <li><p>Is a mutable object <strong>always</strong> a reference? Can you <strong>always</strong> assume that modifying it modifies the original (Unless you specifically make a copy with <code>l2=l1[:]</code> kind of idiom)? </p></li>
  <li><p>Can I assemble a list of all the same references in Python? ie, Some function <code>f(l1)</code> that returns <code>['l1', 'd', 't']</code> if those all those are referring to the same list?</p></li>
  <li><p>It is my assumption that no matter what, the data will remain valid so long as there is some reference to it. </p></li>
  </ol>
  
  <p>ie:</p>
  
  <pre><code>l=[1,2,3]         # create an object of three integers and create a ref to it
  l2=l              # create a reference to the same object
  l=[4,5,6]         # create a new object of 3 ints; the original now referenced 
                    # by l2 is unchanged and unmoved
  </code></pre>