
Dec. 30, 2012
11:04 a.m.
On 30 December 2012 04:59, David Kreuter <dkreuter@gmail.com> wrote:
When I write code for processing graphs it becomes very useful. For example:
def collapse_edge_undirected_graph(a, b): n = Node() n.connected = a.connected + b.connected for x in a.connected: x.connected.replace(a, n) for x in b.connected: x.connected.replace(b, n)
Assuming n.connected is the set of nodes connected to n, why use a list rather than a set? And if you need multi-edges, a dict mapping node to count of edges (i.e. a multiset). Paul.