recursion confusion
Jon Schull
schull at digitalgoods.com
Tue Apr 1 22:09:24 EST 2003
Sometimes recursion befuddles me. This is one of those times.
I want to convert a graph structure into a nested string
For example I want this...
g={0:[], 1:[11], 2:[21, 22], 22:[221,222]}
...to become this
"0, 1[11], 2 [21, 22[221, 222]] "
(with 221 and 222 nested under 22 which is also nested under 2)
Of course, I want this to work for arbitrary nesting, and for strings
as well as numbers.
(Why? in order to create graphviz "record" shapes.)
I suspect there are concise recursive, and not-so-concise
understandable, ways to do this. I'd be grateful for either, but
would prefer the latter.
Thanks very much...
More information about the Python-list
mailing list