['P', ['Q', ['R', ['S', 'T'], ['U', 'V']]]]
This is my list and I need to iterate over it in a specific manner. The output for the following should be :-
P -> Q
Q -> R
R -> S U
S -> T
U -> V
I tried following thing:-
def traverse_mystructure(tree):
queue = [tree]
for list in tree:
print list
traverse_mystructure(list);
I am not able to get this kind of output with the above.Is it possible to obtain this kind of output ?
queue, that's normally use for an iterative solution vs. recursive. BTW: don't uselistas a variable name - it hides the pythonlisttype. Breadth first print will be simpler iteratively (queue).