returning index of minimum in a list of lists

jantod at gmail.com jantod at gmail.com
Thu Jun 22 08:44:40 EDT 2006


JJLaRocque at gmail.com wrote:
> Hi all,
> Is there a simple python function to return the list index of the
> minimum entry in a list of lists?
> ie, for   [[3,3,3,3], [3,3,3,1], [3,3,3,3]]  to return 2,4.
> Or, same question but just for a list of numbers, not a list of lists.
> Thanks,
> Josh

Untested:

items = []
for x, a in enumerate(L):
	for y, b in enumerate(a):
		items.append((b, (x,y)))
x, y = min(items)[1]

You could also change this to a generator:

def f(L):
	for x, a in enumerate(L):
		for y, b in ebumerate(a):
			yield b, (x,y)

x, y = min(f(L))[1]




More information about the Python-list mailing list