bisect and lists of user defined objects (python 3) -
before python 3, used bisect insert user-defined objects list. bisect happy because user-defined object had def __cmp__
defined how compare objects. i've read rationale not supporting cmp in python 3 , i'm fine that. thought fix old code 'decorate' user-defined object turning tuple
(integer, user-defined object).
however, if have list of tuples, , try ...
i = bisect_left([list_of_tuples], (integer, user-defined object))
then error "builtins.typeerror: unorderable types ..."
so, (in python 3) how use bisect lists of items aren't made entirely of things natural sort order?
you need add __lt__
method; used comparisons instead of __cmp__
Comments
Post a Comment