I am having trouble getting my head around how to approach this... I am not asking for an explicit answer, just a heads up about what approach to take. As I have run into problems with every one I have taken so far.
I have a set of nodes:
nodes = { ('A','B'),
('B','C'),
('C','D'),
('C','E'),
('B','E'),
('C','F')}
as a dictionary of sets:
nodedict = { 'A': {'B'},
'C': {'B', 'E', 'D', 'F'},
'B': {'A', 'C', 'E'},
'E': {'C', 'B'},
'D': {'C'},
'F': {'C'} }
what I want to do is to build a structure like this:
for 'A'
A
|
B
_________|_________
| |
C E
_____|_____ |
| | | C
D E F ____|____
| |
D F
so all possible routes from A can be found.
I have been using a list to represent the braches, and then trying to wrap a for loop in a while loop... appending each list with its children if the child is not in the list... but I keep coming unstuck. I sometimes get close, but this is when I am writing explicit for loops and know exactly what I am looking for.
is it best to try to get to one tip first, then backtrack and then to the next tip ...
for x in xs:
...
for a in x:
...
for b in a
but obviously I do not know how deep node 'n' goes... hmmm... any helpful suggestions much appreciated!