BFS in python