On Jan 22, 6:38 am, Paul Rubin <http://[EMAIL PROTECTED]> 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): > > from operator import itemgetter > minindex = min(enumerate(seq), key=itemgetter(1))[1]
Bzzzt! >>> seq = [1000, 9, 8, 7, 2000, 3000] >>> from operator import itemgetter >>> minindex = min(enumerate(seq), key=itemgetter(1))[1] >>> minindex 7 >>> min(enumerate(seq), key=itemgetter(1)) (3, 7) s/[1]/[0]/ or more generally: minindex, minvalue = min(enumerate(seq), key=itemgetter(1)) -- http://mail.python.org/mailman/listinfo/python-list