Hi Richard You suggested A very simple and in my mind reasonable use for this is to build a
representation of a graph, where each node is represented by a list (or some other collection), and the connections are denoted by adding to that collection the nodes that are adjacent (or maybe a tuple of the node and the distance). This naturally creates a recursive structure unless connections are unidirectional and the graph is acyclical (i.e. a tree).
For example, a 3 node fully connected graph might be:
a = [] b = [] c = []
a.append(b) a.append(c) b.append(a) b.append(c) c.append(a) c.append(b)
According to https://en.wikipedia.org/wiki/Graph_theory#Graph, a graph is an ordered pair
G = (V, E) where V is a set of vertices, and E is a set of edges, where an edge is an unordered pair of vertices.
You've given the complete graph on 3 vertices (although without explicitly stating the vertex set V). https://en.wikipedia.org/wiki/Complete_graph If we use the wikipedia definition (with vertices 'a', 'b' and 'c') we have
V = {'a', 'b', 'c'} E = {{'a', 'b'}, {'a', 'c'}, {'b', 'c'}}
I've shown how to represent graphs, by directly translating the mathematical definition into Python (without introducing any additional classes). You've produced a different way to represent graphs. Mathematically, your representation is this. There is a set V of vertices. Further, for each v in V there is associated a subset V_v of V. Further, if w in V_v then v in V_w. I wouldn't call what you've written down the Python representation of this mathematical definition. To explain this, I'll write down what I think it should be. Suppose G is a graph with vertices {'a', 'b', 'c', 'd'}. Using a dict to represent the map that v goes to V_v, we can write G as { 'a': {...}, 'b': {...}, # etc 'e': {...}, } My initial post suggests that, purely on the basis of the loop in the data structure, there's a code smell in the representation you provided. I'd say that not agreeing with its own mathematical definition is a code smell (or worse). I'll put it another way. Suppose our vertices are called (or represent) Alice, Bob, Carol, Dave and Eve. Now let G be the graph whose edges represent the existence of cryptographically secure communication between X and Y. I claim that your code isn't able to represent such a graph. Thank you Richard for forcing me to think things through and find what I consider to be a flaw in the code you supplied. -- Jonathan