[Python-ideas] proposed methods: list.replace / list.indices

David Kreuter dkreuter at gmail.com
Sun Dec 30 10:24:31 CET 2012


On Sun, Dec 30, 2012 at 10:04 AM, Paul Moore <p.f.moore at gmail.com> wrote:

> On 30 December 2012 04:59, David Kreuter <dkreuter at 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20121230/b1d13493/attachment.html>


More information about the Python-ideas mailing list