'Removes the given Node (and all its edges) or Edge from the graph.
Note: removing Edge a->b does not remove Edge b->a.'

def remove(self, x):

    if (isinstance(x, Node) and (x.id in self)):
        self.pop(x.id)
        self.nodes.remove(x)
        x.graph = None
        for e in list(self.edges):
            if (x in (e.node1, e.node2)):
                if (x in e.node1.links):
                    e.node1.links.remove(x)
                if (x in e.node2.links):
                    e.node2.links.remove(x)
                self.edges.remove(e)
    if isinstance(x, Edge):
        self.edges.remove(x)
    self._adjacency = None
