While we're talking about annoyances

Paul Rubin http
Sun Apr 29 12:33:41 EDT 2007


Steven D'Aprano <steve 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))



More information about the Python-list mailing list