[Python-ideas] proposed methods: list.replace / list.indices
Paul Moore
p.f.moore at gmail.com
Sun Dec 30 10:04:32 CET 2012
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.
More information about the Python-ideas
mailing list