Weighted graph

This line is problematic.  Why not just let the original KeyError bubble up to the top?  When you except and re-raise the same error, all you really accomplish is obscuring the source of the error: in a stack trace, I'll be pointed to this line, rather than the line where the original KeyError was raised, which makes debugging a bit harder.