title: Python sorted() key function weirdness
body: <p>While I was debugging some illogical behavour I came to the following weirdness in Python 2.5 <em>sorted()</em> function calls:</p>
  
  <pre><code>&gt;&gt;&gt; aa = [10, 5, 20]
  &gt;&gt;&gt; sorted(range(len(aa)))
  [0, 1, 2]
  sorted(range(len(aa)), key=lambda a: aa[a])
  [1, 0, 2]
  sorted(range(len(aa)), key=lambda a: -aa[a])
  [2, 0, 1]
  </code></pre>
  
  <p>First two calls work as expected, but the last one is imho simply <strong>wrong</strong>! It should be: [1, 2, 0].</p>
  
  <p>After further experiments for trying to come to the root of the problem I came to this (does not use lambda or negation operation, but it is otherwise the same problem):</p>
  
  <pre><code>&gt;&gt;&gt; bb = [-10, -5, -20]
  &gt;&gt;&gt; sorted([0, 1, 2], key=bb.__getitem__)
  [2, 0, 1]
  </code></pre>
  
  <p>Even things like following don't work and show that double negation works again:</p>
  
  <pre><code>&gt;&gt;&gt; bb = [-10, -5, -20]
  &gt;&gt;&gt; def fun(i):
  ...    return bb[i]
  &gt;&gt;&gt; sorted([0, 1, 2], key=fun)
  [2, 0, 1]
  &gt;&gt;&gt; def fun2(i):
  ...     return -bb[i]
  &gt;&gt;&gt; sorted([0, 1, 2], key=fun2)
  [1, 0, 2]
  </code></pre>
  
  <p>Am I losing my mind or where is the problem? Or why doesn't Python 3.x have the <em>cmp</em> argument that used to work fine (compatibility is the reason why I am not using it)?</p>