On 10/30/07, Greg Ewing <[EMAIL PROTECTED]> wrote: > Adam Olsen wrote: > > for a, b in zip(self.data, other.data): > > result = richcmp(a, b, ordered) > > if result: > > return result > > That can't be right, because there are *three* possible > results you need to be able to distinguish from comparing > a pair of elements: "stop and return True", "stop and > return False", and "keep going". There's no way you can > get that out of a boolean return value.
It's not strictly a boolean value. If ordered is false then you interpret it as either a false value or a true value (but it may return -1 or +1 for the true values.) If ordered is true then it may be -1, 0/false, +1, or raise a TypeError if ordering is unsupported. > def __cmp__(self, other): > for a, b in zip(self.items, other.items): > result = cmp(a, b) > if result != 0: > return result > return 0 > > Which is actually the same as it is now, with an added > bit of It Just Works behaviour: if any of the element > comparisons gives UnequalButNotOrdered, then the whole > sequence gets reported as such. So the difference between our two approaches is that mine uses a flag to indicate if a TypeError should be raised, while yours adds an extra return value. Mine does have a small benefit: list currently exits early if it's only testing for equality and the lengths differ, which couldn't be done with your API. -- Adam Olsen, aka Rhamphoryncus _______________________________________________ Python-3000 mailing list Python-3000@python.org http://mail.python.org/mailman/listinfo/python-3000 Unsubscribe: http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com