[issue5669] Extra heapq nlargest/nsmallest option for including ties

George Sakkis report at bugs.python.org
Thu Apr 2 19:56:58 CEST 2009


George Sakkis <george.sakkis at gmail.com> added the comment:

There's nothing special about my use cases; I'd even go as far as to
suggest that this is more often than not the desired behavior in general.

Say that you have to select the top 3 chess players and there are two
players with equal Elo rating at positions 3 and 4. Whom do you select?
Without a tie-breaking method, it's only fair to select both and return
4 players in total instead of exactly 3. 

The current method selects "arbitrarily" (at least with respect to the
key function) which of the equally-keyed items to return. This is
necessary in some cases by external constraints (say, you can hire only
1 person) but there are quite a few cases that "fairness" is more
important than a hard constraint on the number of returned objects.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue5669>
_______________________________________


More information about the Python-bugs-list mailing list