Kaz Kylheku wrote:

> Would that be a case-insensitive lexicographic comparison, or
> case-insensitive? How do you specify what kind of less-than and equal
> you want to do?

class Key(object):
    def __init__(self, value, key):
        self.keyval = key(value)
        self.key = key
    def __lt__(self, other):
        return self.keyval < self.key(other)
    def __gt__(self, other):
        return self.keyval > self.key(other)

items = ["Alpha", "Beta", "Delta", "Gamma"]
print binarySearch(items, Key("DELTA", str.lower)) # 2

You /can/ teach an old duck new tricks :-)

Peter
 

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to