maximum() efficency

Steve R. Hastings steve at
Mon Mar 27 01:31:47 CEST 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.

Steve R. Hastings    "Vita est"
steve at

More information about the Python-list mailing list