On 12/05/2013 11:52 AM, Steven D'Aprano wrote:
There is a name for this: it is called a RANK TABLE. In the example
given:

values = [3, 1, 2, 5, 4]

the rank table gives the rank of each element, that is, the position
they would get after sorting. In this case, the rank table is not
terribly exciting, because the items are equal to their ranks, less 1
because Python counts indexes from 0 rather than 1:

Yes, that's it; and there are two kinds of such rank tables, in principle, depending on what is the key of the table:
* either the index the the original (unsorted) list
* or the value (if it can be a dict key)

["foo", "bar", "baz"] -->
* {0:2, 1:0, 2:1}
* {"foo":2, "bar":0, "baz":1}
(This is hard to get right with 0-based indexes! We don't think that way -- at least _I_ don't.)

But, as already implicitely shown by Steven, in case keys are the original indexes, one can as well make it a plain list:
* [2, 0, 1]

Denis
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to