Click here to see the full article post
In Python Approach#1:
for node in queue: if node: .... queue.append(nei)
modifies the list
queue while iterating over it. This may result in undefined behavior.
@xivaxy I think every implementation of Python ever will have it always work the way we want it to, but as it's technically unspecified behavior, you are right that it would be incorrect to write the code this way. I decided to change the code anyways to not use this kind of pattern.