index of min element of sequence

Paul Rubin http
Mon Jan 21 15:56:14 EST 2008


John Machin <sjmachin at lexicon.net> writes:
> s/[1]/[0]/ or more generally:

Oops, got two spellings confused.  Originally was going to use

 from itertools import count, izip
 min(izip(seq, count()))[1]

but did it with enumerate instead.  I don't know which is actually
faster.

> minindex, minvalue = min(enumerate(seq), key=itemgetter(1))

Cool, I like this best of all.  Or alternatively,

  minindex, minvalue = min(izip(seq, count()))



More information about the Python-list mailing list