index of min element of sequence

John Machin sjmachin at lexicon.net
Mon Jan 21 16:47:06 EST 2008


On Jan 22, 7:56 am, Paul Rubin <http://phr...@NOSPAM.invalid> wrote:
> John Machin <sjmac... 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()))

Bzzzt #2!

>>> from itertools import count, izip
>>> min(izip(seq, count()))
(7, 3)




More information about the Python-list mailing list