I am getting an error of "list index out of range" in this part of the code "edgeid[I] != edgeid[i+1]"

I already tried to change the array but it didn't work.
This is happening because the function match below is returning an empty list. Do you know why this is happening?
