I've got a problem with find a way for visit a particular list of list in python.
this is the situation:
I've got a list of list like this with some 1 and some 0:
matrix =
[
[0,0,0,0,0,0,0],
[0,1,1,1,1,0,1],
[0,1,1,1,1,0,1],
[0,1,1,1,1,0,1],
[0,0,0,0,0,0,0],
]
so I enter in the list of list in a specific coordinate like this
y = 3
x = 3
and from this position I need to mark (example with a 2) all the coordinates near of the start position where 1 is in the box.
Stop when I've marked all the positions close of the starting point with 2.
This is the expected result:
expected_matrix =
[
[0,0,0,0,0,0,0],
[0,2,2,2,2,0,1],
[0,2,2,2,2,0,1],
[0,2,2,2,2,0,1],
[0,0,0,0,0,0,1],
]
Edit:
I can't scan all the lists, because I'm not interested to mark every 1 but only the closest (alongside of a 0 inside the starting point coordinates (rows ad cols)) of the starting point
Thanks.