← Back to Graphs Part 1

Find Position

3 of 9

Exercise 2: Find Position

Your Task

Write a function find_position(grid, target) that:

  • Returns the (row, col) of the first occurrence of target in the grid (scanning row by row, left to right)
  • Returns None if the value isn't found

Examples

grid = [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ] print(find_position(grid, 5)) # (1, 1) print(find_position(grid, 7)) # (2, 0) print(find_position(grid, 10)) # None

Hints

Try it yourself

Code: Find Position

Loading Python runtime…
Python …
Loading...
bash
$ Click "Run" to execute your code...