bearophile: > I don't like your solution, this class was already slow enough. Don't > use unbound methods with this class :-)
Sorry for raising this discussion after so much time. Another possibile solution is to use the normal methods for the normal case, and replace them only if key is present (this reduces problems with unbound methods but you may use the wrong method). Example: def __init__(self, sequence=None, key=None, inplace=False): ... if key is None: ... else: ... self.pop = self.__pop_key ... def pop(self): return heappop(self._heap) def __pop_key(self): return heappop(self._heap)[2] Someone else has done something similar: http://groups.google.com/group/comp.lang.python/browse_thread/thread/e61ba58c9722bf51/ http://sourceforge.net/tracker/index.php?func=detail&aid=1162363&group_id=5470&atid=305470 Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list