Efficient Rank Ordering of Nested Lists

pablo.mitchell at gmail.com pablo.mitchell at gmail.com
Sat Aug 4 14:08:54 EDT 2007


On Aug 3, 9:20 am, pyscottish... at hotmail.com wrote:
> On Aug 2, 10:20 pm, "pablo.mitch... at gmail.com"
>
>
>
> <pablo.mitch... at gmail.com> wrote:
> > A naive approach to rank ordering (handling ties as well) of nested
> > lists may be accomplished via:
>
> >    def rankLists(nestedList):
> >       def rankList(singleList):
> >           sortedList = list(singleList)
> >           sortedList.sort()
> >           return map(sortedList.index, singleList)
> >       return map(rankList, nestedList)
>
> >    >>> unranked = [ [ 1, 2, 3, 4, 5 ], [ 3, 1, 5, 2, 4 ], [ -1.1, 2.2,
> > 0, -1.1, 13 ] ]
> >    >>> print rankLists(unranked)
>
> >    [[0, 1, 2, 3, 4], [2, 0, 4, 1, 3], [0, 3, 2, 0, 4]]
>
> > This works nicely when the dimensions of the nested list are small.
> > It is slow when they are big.  Can someone suggest a clever way to
> > speed it up?
>
> Isn't there something wrong with the ordering?
>
> Pablo's answers are:
> [ 1, 2, 3, 4, 5 ] == [0, 1, 2, 3, 4]  correct
>
> [ 3, 1, 5, 2, 4 ] == [2, 0, 4, 1, 3] wrong?
>
> [ -1.1, 2.2, 0, -1.1, 13 ] == [0, 3, 2, 0, 4] wrong?
>
> Doing it in my head I get:
> [ 3, 1, 5, 2, 4 ] == [ 1, 3, 0, 4, 2 ]
>
> [ -1.1, 2.2, 0, -1.1, 13 ] == [0, 3, 2, 1, 4]
>
> What gives?
>
> Did I misunderstand what "rank ordering (handling ties as well)" means?

There are many ways to skin this cat.  I am considering the following
approach:

http://en.wikipedia.org/wiki/Rank_order#Standard_competition_ranking_.28.221224.22_ranking.29




More information about the Python-list mailing list