Re: index of min element of sequence

2008-01-21 Thread Paul Rubin
John Machin <[EMAIL PROTECTED]> writes: > >>> from itertools import count, izip > >>> min(izip(seq, count())) > (7, 3) Serves me right for cutting and pasting. minvalue, minindex = min(izip(seq, count())) -- http://mail.python.org/mailman/listinfo/python-list

Re: index of min element of sequence

2008-01-21 Thread John Machin
On Jan 22, 7:56 am, Paul Rubin wrote: > John Machin <[EMAIL PROTECTED]> 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 en

Re: index of min element of sequence

2008-01-21 Thread Paul Rubin
John Machin <[EMAIL PROTECTED]> 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 =

Re: index of min element of sequence

2008-01-21 Thread Peter Otten
Roger Miller wrote: > On Jan 21, 8:48 am, Peter Otten <[EMAIL PROTECTED]> wrote: > >> Neal Becker wrote: >> > What's a good/fast way to find the index of the minimum element of a >> > sequence? > ... > >> >>> min(xrange(len(items)), key=items.__getitem__) > ... > > Or just >items.index(min(

Re: index of min element of sequence

2008-01-21 Thread John Machin
On Jan 22, 6:38 am, Paul Rubin wrote: > Neal Becker <[EMAIL PROTECTED]> writes: > > What's a good/fast way to find the index of the minimum element of a > > sequence? (I'm fairly sure sorting the sequence is not the fastest > > approach) > > Python 2.5 (untested): > >

Re: index of min element of sequence

2008-01-21 Thread Roger Miller
On Jan 21, 8:48 am, Peter Otten <[EMAIL PROTECTED]> wrote: > Neal Becker wrote: > > What's a good/fast way to find the index of the minimum element of a > > sequence? ... > >>> min(xrange(len(items)), key=items.__getitem__) ... Or just items.index(min(items)) I found this to be significantly

Re: index of min element of sequence

2008-01-21 Thread Paul Rubin
Neal Becker <[EMAIL PROTECTED]> writes: > What's a good/fast way to find the index of the minimum element of a > sequence? (I'm fairly sure sorting the sequence is not the fastest > approach) Python 2.5 (untested): from operator import itemgetter minindex = min(enumerate(seq), key=itemgett

Re: index of min element of sequence

2008-01-21 Thread Peter Otten
Neal Becker wrote: > What's a good/fast way to find the index of the minimum element of a > sequence? (I'm fairly sure sorting the sequence is not the fastest > approach) >>> items = "defbhkamnz" >>> min(xrange(len(items)), key=items.__getitem__) 6 >>> items[6] 'a' Peter -- http://mail.python.

index of min element of sequence

2008-01-21 Thread Neal Becker
What's a good/fast way to find the index of the minimum element of a sequence? (I'm fairly sure sorting the sequence is not the fastest approach) -- http://mail.python.org/mailman/listinfo/python-list