Message76203
I agree you can get around this with defining __cmp__, however same goes
to "sort" and it was added anyway.
My take on it is that sometimes I need to find something in a big list
of objects, and I don't like to do DSU and not add __cmp__ to the
objects (since some of the lists might be sorted by different attributes
- say one list for time and one line for price).
I'd prefer if we do implement "key" and add a warning in the docs it
might slow you down. Which what will happen in the case of __cmp__ anyway.
I don't see why the "key" function should be called all the time on
inserted item, it's very easy to cache this value
def bisect(a, x, lo=0, hi=None, key=lambda x: x):
assert low >= 0, "low must be non-negative"
hi = hi or len(a)
x_key = key(x)
while lo < hi:
mid = (lo+hi)//2
if x_key < key(a[mid]): hi = mid
else: lo = mid+1
return lo
(I'd also wish for "identity" built in, however this is another subject :) |
|
Date |
User |
Action |
Args |
2008-11-21 20:45:20 | tebeka | set | recipients:
+ tebeka, rhettinger, mark.dickinson |
2008-11-21 20:45:20 | tebeka | set | messageid: <1227300320.56.0.26201189374.issue4356@psf.upfronthosting.co.za> |
2008-11-21 20:45:19 | tebeka | link | issue4356 messages |
2008-11-21 20:45:18 | tebeka | create | |
|