Comparing objects - is there a maximum object?

Chris Brew cbrew at
Thu Sep 4 21:24:38 CEST 2003

I've just been writing some code to merge items from
a collection of streams, where each item has a key,
and each stream is known to be sorted in ascending
order of key. I read all the streams once, then
pick the minimum element of the results, replace
it with a new one read from the corresponding 
stream, and repeat. 

Thing is, what happens at end of file? I'd like to
do it by making the streams that are finished
return some object (call it endmarker) such
that min(x,endmarker) always returns x. That way,
when all the streams are returning endmarker, we
would be done. And I'd like my code to work the same
no matter what kind of thing the streams are
returning, so I want endmarker to be a generic
maximum object.

The Python documentation says:

The operators <, >, ==, >=, <=, and != compare the values of two
objects. The objects need not have the same type. If both are numbers,
they are converted to a common type. Otherwise, objects of different
types always compare unequal, and are ordered consistently but

so  (unless this has been superseded) it doesn't seem that there is
such an object. Any suggestions? I notice that empirically max(x,None)
seems to be always x, but again I suppose I shouldn't count on that.


More information about the Python-list mailing list