class myGraph(nx.Graph):

    def __eq__(self, other):
        return nx.is_isomorphic(self, other)

def __hash__(self):
    return hash(tuple(sorted(self.degree().values())))
if __name__ == '__main__':
    G1 = myGraph([(1, 2)])
G2 = myGraph([(2, 3)])
G3 = myGraph([(1, 2), (2, 3)])
print(G1.__hash__(), G1.edges())
print(G2.__hash__(), G2.edges())
print(G3.__hash__(), G3.edges())
print(G1 == G2)
print(G1 == G3)
graphs = {}
graphs[G1] = 'G1'
graphs[G2] = 'G2'
graphs[G3] = 'G3'
print(list(graphs.items()))
'Isomorphic' comparison of NetworkX Graph objects instead of the default 'address' comparison