Python Forum

Full Version: Node Flow Generation in Python
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hey all,

I was working on a project (code included). I wanted to simulate the flow of several nodes. Each node can go to several other nodes. This is stored in a dictionary.

Numbers = [A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q] = Letters = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17]

road_key = {A: (B, D), B: (C, E, H), C: (B,D,F), D: (A,C,F,G), E: (B,K,F), F: (C,D,E), G: (D, J, M), H: (B, K, I), I: (H,J,L), J: (I,P,G), K: (E,H,N), L: (I,M,N,O), M:(G,P,L), N:(L,Q,K), O:(L,Q), P: (J,Q,M), Q:(N,O,P)}
letter_list = []
def flow(letter_key):
	letter_list.append(letter_key)
	

flow(A)
I want to start the flow through function flow(), which takes a key. I want to continue flowing down a chain, until the letter_list is full to 17 numbers. Again, I want to generate every possible combination of letters. So, if I were to flow(A), I want to generate a flow of A -> B or D, from B or D, going to (C,E,H) or (B,D,F), and on and on.

I am having trouble figuring out a way to store every individual iteration, as I think that would take a lot of lists/containers for each possible combination.