python language: infimum and supremum of integers

Alex Martelli aleax at aleax.it
Wed Apr 23 18:07:26 EDT 2003


Charlie Reiman wrote:

> Alex Martelli <aleax at aleax.it> writes:
> 
>> <posted & mailed>
>> > 
>> For your algorithm, why not just, for example:
>> 
>> class Infimum:
>>     def __cmp__(self, other): return -1
>> infimum = Infimum()
>> 
>> class Supremum:
>>     def __cmp__(self, other): return 1
>> supremum = Supremum()
>> 
>> as coded these have obvious anomalies, e.g. infimum < infimum -- but
>> those are easy to remove if they give problems to your algorithm.
> 
> 
> Are there any dangers in something like this:
> 
> a = [1, infimum, infimum]
> a.sort()

Quite possibly -- so IF your algorithms sorts lists, then the "easy
to remove" anomalies should be removed.

> Should the __cmp__ methods return 0 for equality (identity, in this
> case)?

If you need sorting, yes -- "return (other is not self) and -1" will
suffice.  But, should you never need to compare infimum to itself,
then the precaution, cheap as it may be, won't pay for itself.  You
pays your money and you takes your choices.


Alex





More information about the Python-list mailing list