ruben_pants
ruben_pants

Reputation: 41

Determine number of row in matrix

If I have a matrix, and a row, how can I determine the how many-th row it is in the matrix?

For example, if i got a matrix [[1,2,3],[4,5,6],[7,8,9]] and I got the row [4,5,6], then I want to know it's the second row a.k.a. board[1].

(This is just a small example, but it is supposed to be checked on bigger matrices)

Upvotes: 1

Views: 34

Answers (1)

ohmu
ohmu

Reputation: 19780

If you have the matrix (list of lists):

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

You can get its position by using .index():

>>> board.index([4, 5, 6])
1

Upvotes: 2

Related Questions