locate items in matrix (index of lists of lists)

Alexzive zasaconsulting at gmail.com
Fri Mar 20 11:50:38 CET 2009

Hello there,

let's suppose I have the following matrix:

mat = [[1,2,3], [3,2,4], [7,8,9], [6,2,9]]

where [.. , .. , ..] are the rows.

I am interested into getting the "row index" of all the matrix rows
where a certain number occurs.
For example for 9 I should get 2 and 3 (starting from 0).
For 10 I should get an error msg (item not found) and handle it.

How to get the"row indexes" of found items?

In practice I am looking for an equivalent to "list.index(x)" for the
case "lists of lists"

Many Thanks!

PS: this is just a simplified example, but I have actually to deal
with large matrices [~500000 * 4]

More information about the Python-list mailing list