title: Python self-referential list produces weird output on sorted
body: <p>I recently came across a weird discrepancy when trying to sort self-referential lists using <code>.sort()</code> and <code>sorted()</code>. I was hoping someone could shed some light on this. The code in question is the following:</p>
  <pre class="lang-py prettyprint-override"><code>lst = [1, 2, 3]
  
  lst[0] = lst
  lst[1] = lst
  lst[2] = lst
  
  print(lst)
  
  print(sorted(lst))
  
  lst.sort()
  
  print(lst)
  </code></pre>
  <p>The above code produces the following output:</p>
  <pre class="lang-sh prettyprint-override"><code>[[...], [...], [...]]
  [[[...], [...], [...]], [[...], [...], [...]], [[...], [...], [...]]]
  [[...], [...], [...]]
  </code></pre>
  <p>It's the output from <code>print(sorted(lst))</code> that baffles me. Wonder if it is some form of recursion that's causing it?</p>