title: Sort a list by the number of occurrences of the elements in the list
body: <p>I want to sort a list by the number of occurrences of the elements in the list.<br>
  When I use this form:    </p>
  
  <pre><code>A=[2,1,3,4,2,2,3]
  A.sort(key=lambda x:A.count(x))  
  print(A)
  </code></pre>
  
  <p>the result is not what I want: <code>[2, 1, 3, 4, 2, 2, 3]</code>.<br>
  But, when I write like it using <code>sorted</code>:    </p>
  
  <pre><code>B=sorted(A,key=lambda x:A.count(x))
  print(B)
  </code></pre>
  
  <p>the result is right: <code>[1, 4, 3, 3, 2, 2, 2]</code>.<br>
  what's the reason for this behavior?</p>