index of min element of sequence

Peter Otten __peter__ at web.de
Mon Jan 21 13:48:18 EST 2008


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



More information about the Python-list mailing list