returning index of minimum in a list of lists
jwelby
julius.welby at gmail.com
Wed Jun 21 12:43:00 EDT 2006
def minIndexFinder(seq):
mins = []
listIndex = 0
result = []
for item in seq:
mins.append([listIndex,min(item),item.index(min(item))])
listIndex += 1
lowest = min([x[1] for x in mins])
for item in mins:
if item[1] == lowest:
result.append([item[0], item[2]])
return result
A bit more verbose, but maybe slightly more readable??
I probably should have used enumerate like Paul did.
For the index of the *first* (or only) occurence of the minimum value
in a list of numbers you can just use:
seq.index(min(seq))
More information about the Python-list
mailing list