maximum() efficency

Steve R. Hastings steve at hastings.org
Sun Mar 26 18:31:47 EST 2006


On Sun, 26 Mar 2006 10:34:16 -0700, Steven Bethard wrote:
> What's the original?



def minimum(cmp, lst):
  """minimum(cmp, lst)

  Returns the minimal element in non-empty list LST with elements
  compared via CMP() which should return values with the same semantics
  as Python's cmp().  If there are several minimal elements, the last
  one is returned.
  """

  if not lst:
    raise ValueError, 'empty list'

  minval = lst[0]

  for i in xrange(1, len(lst)):
    v = lst[i]
    if cmp(minval, v) > 0:
      minval = v

  return minval



This is from Google's "goopy" package.

http://goog-goopy.sourceforge.net/

-- 
Steve R. Hastings    "Vita est"
steve at hastings.org    http://www.blarg.net/~steveha




More information about the Python-list mailing list