This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author tebeka
Recipients mark.dickinson, rhettinger, tebeka
Date 2008-11-21.20:45:18
SpamBayes Score 2.17892e-12
Marked as misclassified No
Message-id <>
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:20tebekasetrecipients: + tebeka, rhettinger, mark.dickinson
2008-11-21 20:45:20tebekasetmessageid: <>
2008-11-21 20:45:19tebekalinkissue4356 messages
2008-11-21 20:45:18tebekacreate