| 1 | initial version |
A slightly slightly improved solution
def twin_reduced_graph(G):
r"""
Return a twin reduced graph.
Vertices `u` and `v` are twins if `N(u) == N(v)`.
"""
twins = set()
to_delete = []
for v in G:
neigh = frozenset(G.neighbor_iterator(v))
if neigh in twins:
to_delete.append(v)
twins.add(neigh)
H = G.copy(immutable=False)
H.delete_vertices(to_delete)
return H
| 2 | No.2 Revision |
A slightly slightly improved solution
def twin_reduced_graph(G):
r"""
Return a twin reduced graph.
Vertices `u` and `v` are twins if `N(u) == N(v)`.
"""
twins = set()
to_delete = []
for v in G:
neigh = frozenset(G.neighbor_iterator(v))
if neigh in twins:
to_delete.append(v)
else:
twins.add(neigh)
H = G.copy(immutable=False)
H.delete_vertices(to_delete)
return H
Copyright Sage, 2010. Some rights reserved under creative commons license. Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.