def __eq__(self, other):
def nodes_eq():<EOL><INDENT>for each in self:<EOL><INDENT>if (not other.has_node(each)): return False<EOL><DEDENT>for each in other:<EOL><INDENT>if (not self.has_node(each)): return False<EOL><DEDENT>return True<EOL><DEDENT>def edges_eq():<EOL><INDENT>for edge in self.edges():<EOL><INDENT>if (not other.has_edge(edge)): return False<EOL><DEDENT>for edge in other.edges():<EOL><INDENT>if (not self.has_edge(edge)): return False<EOL><DEDENT>return True<EOL><DEDENT>try:<EOL><INDENT>return nodes_eq() and edges_eq()<EOL><DEDENT>except AttributeError:<EOL><INDENT>return False<EOL><DEDENT>
Return whether this graph is equal to another one.

@type other: graph, digraph
@param other: Other graph or digraph

@rtype: boolean
@return: Whether this graph and the other are equal.