You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

15 lines
359 B

from collections import deque
def visit_connected_states(state):
visit = deque()
already_visited = set()
visit.append(state)
while visit:
state = visit.popleft()
if state in already_visited:
continue
already_visited.add(state)
yield state
visit.extend(t.target for t in state.transitions)