Is this example about weight in graph right?

Inside the Graph exercise in 7. Adding Weight there is an example that comes with the exercise:

railway = Graph()

callan = Vertex(‘callan’)
peel = Vertex(‘peel’)
harwick = Vertex(‘harwick’)


Travel-time between callan and peel: 12

railway.add_edge(callan, peel, 12)

Travel-time between harwick and callan: 7

railway.add_edge(harwick, callan, 7)


{ ‘peel’: 12 }


{ ‘callan’: 7 }

But I think there is something wrong.

When railway was created no argument was passed, so it is a undirected graph. Right?

So when new edges were added I think Callan should have as edges (peel: 12 and harwick: 7) and not just (peel:12) as the example prints out.

If not, I think I misunderstood how directed or undirrected graphs work. Can someone help me out?


Aren’t you answering that yourself?
If I said yes/no I’m not sure we’d be thinking of the same thing, is there something else, related that you meant to ask? Maybe related to where the source of the problem is. But you can probably do a lot yourself to narrow that down - what code is supposed to be responsible for making it behave that way?

You could draw vertices and circles and edges as lines between them, adding an edge connects two vertices and to look at the edges connected to one vertex … well look at it, yeah, and yeah those edges go both ways if it’s undirected

This code is an example that code academy gave me and I think the example is wrong. I wanted to know if I’m right or wrong in my thinking.

Didn’t you write the code that adds edges?

  1. Tab over to .
    Inside Graph , alter .add_edge() so it also takes an additional argument of weight .
    This argument should also default to 0 .

it’s that code, isn’t it