visited = set(visited)
visited.add(self)
for neighbor in self.neighbors:
    if neighbor.powered or neighbor.is_connected_to_powered(visited):
        return True
return False
How to recursively check for attributes in an object?