bisect uses __cmp__()?
jepler at unpythonic.net
Tue Jul 29 23:59:09 CEST 2003
On Tue, Jul 29, 2003 at 04:05:46PM -0400, Gary Robinson wrote:
> I'm wondering if bisect.insort is guaranteed to use a __cmp__ method, for
> now and for future python versions, if it exists, for the items being
I don't know for certain what (if anything) is guaranteed, but my guess is that
insort is defined to use only the < operator to compare items. This
means that you can meet the requirements of the bisect module by
defining __cmp__ or by defining __lt__ (or even by defining __gt__!). See
for how "rich comparison" works to perform comparisons. __cmp__ is used
"if rich comparison is not defined". Thus, existing code with __cmp__
still works just fine.
More information about the Python-list