
On Sun, Dec 30, 2012 at 10:04 AM, Paul Moore <p.f.moore@gmail.com> wrote:
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.
Ah, that's because in that specific case I'm processing flow graphs. A node with two outgoing edges represents an 'if'. The order does matter. [1] is where the flow continues when the condition evaluates to true. [0] for false. Forgot to mention that.