We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Python's default arguments are evaluated when the function is defined, not when it is called. This means that the default value adj_list=[] in vertex.__init__ is a single list which is reused every time you call vertex(). Thus every vertex ends up with the exact same adjacency list, and you get a complete graph.
Roads and Libraries
You are viewing a single comment's thread. Return to all comments →
Python's default arguments are evaluated when the function is defined, not when it is called. This means that the default value adj_list=[] in vertex.__init__ is a single list which is reused every time you call vertex(). Thus every vertex ends up with the exact same adjacency list, and you get a complete graph.
Here is a working __init__:
where I took out your other member variables, because you don't need them.