While we're talking about annoyances

Arnaud Delobelle arnodel at googlemail.com
Sun Apr 29 12:48:46 EDT 2007


On Apr 29, 5:33 pm, Paul Rubin <http://phr...@NOSPAM.invalid> wrote:
> Steven D'Aprano <s... at REMOVE.THIS.cybersource.com.au> writes:
> > I recently needed to write a function to generate a rank table from a
> > list. That is, a list of ranks, where the rank of an item is the position
> > it would be in if the list were sorted:
>
> > alist = list('defabc')
> > ranks = [3, 4, 5, 0, 1, 2]
>
> fst = operator.itemgetter(0)   # these should be builtins...
> snd = operator.itemgetter(1)
>
> ranks=map(fst, sorted(enumerate(alist), key=snd))

This is what the OP calls the index table, not the ranks table (both
are the same for the example above, but that's an unfortunate
coincidence...)

--
Arnaud




More information about the Python-list mailing list