Message343549
Can you not use functools.cmp_to_key() for this?
Here's an example:
>>> import bisect, functools
>>> l = [('f', 5), ('d', 3), ('c', 2), ('b', 1), ('a', 0)]
>>> def cmp(a, b):
... if a > b: return -1
... if a < b: return 1
... return 0
...
>>> bisect.bisect(l, ('e', 4), key=functools.cmp_to_key(cmp))
1
>>> l
[('f', 5), ('d', 3), ('c', 2), ('b', 1), ('a', 0)]
>>> bisect.insort(l, ('e', 4), key=functools.cmp_to_key(cmp))
>>> l
[('f', 5), ('e', 4), ('d', 3), ('c', 2), ('b', 1), ('a', 0)] |
|
Date |
User |
Action |
Args |
2019-05-26 14:25:52 | remi.lapeyre | set | recipients:
+ remi.lapeyre, rhettinger, terry.reedy, gregory.p.smith, jafo, tebeka, mark.dickinson, alex, milko.krachounov, dmtr, bls, martin.panter, Dima.Tisnek, yselivanov, NeilGirdhar, josh.r, ericreynolds, wumpus, flyingosprey |
2019-05-26 14:25:52 | remi.lapeyre | set | messageid: <1558880752.33.0.822360328328.issue4356@roundup.psfhosted.org> |
2019-05-26 14:25:52 | remi.lapeyre | link | issue4356 messages |
2019-05-26 14:25:52 | remi.lapeyre | create | |
|