Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Python-Min/max of seq WITHOUT min() and max()

Name: Anonymous 2007-02-08 21:02

Given a sequence such as x = [5, 9, 0, -14], I need to find the min and max without sorting the sequence or by using min() and max().  I've been instructed to use loop constructs, but I can't figure out how to do so.  Help is greatly appreciated.

Name: Anonymous 2007-02-09 18:42

>>9
You can easily add an int, float or long subclass that supports infinity.

Start like:
class PosInfinityType: pass
PosInfinity = PosInfinityType()
class NegInfinityType: pass
NegInfinity = NegInfinityType()

Then go on like:
class iint(int):

and redefine all the special methods (double underscored div, add, eq, lt, etc, check the docs). It's pretty easy.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List