I am trying to perform BFS on this graph starting from node 16. But my code is giving erroneous output. Can you please help me out. Thanks.
visited_nodes = set()
queue = 
pardaught = dict()
exclu = list()
path = set()
for node in queue:
neighbors = G.neighbors(node)
queue.extend([n for n in neighbors if n not in visited_nodes])
newG = G.subgraph(path)
The cause of your problem is that you are removing things from (the start of) queue while looping through it.
integer_list = [1,2,3] next_int = 4 for integer in integer_list: print integer integer_list.remove(integer) integer_list.append(next_int) next_int += 1