Range Operation pre-PEP

Andrew Dalke dalke at acm.org
Fri May 11 21:17:05 EDT 2001


Rainer Deyke wrote:
>These arguments to 'min' are all
>homogeneous because they are treated identically; you can even change their
>order and still get the same result.

That's not necessarily true, although I can't think of any
counterexamples which are also useful.  Here's a made-up one.

>>> class BadCmp:
...  def __init__(self): self.count = 0
...  def __cmp__(self, other):
...   self.count = self.count + 1
...   return (self.count % 3) - 1
...
>>> min([BadCmp(), 0, 1])
1
>>> min([BadCmp(), 1, 0])
0
>>>

                    Andrew
                    dalke at acm.org






More information about the Python-list mailing list