is there an easy way to parse a nested list ?

Stef Mientki stef.mientki at
Mon Mar 16 00:44:25 CET 2009


I need to parse a nested list, given as a string, like this

line = " A  [  B  [ C+2 ] + 3 ] "

( I probably can do it with find, but I guess that's not the most 
elegant way, besides recusrion is not my strongest point)

which should be parsed so I get an list from inner to outer side (don't 
know if these are the correct words),
but I should like to have a list or tuple for tis case:

parsed = [ C+2,  B[C+2]+3,   A  [  B  [ C+2 ] + 3 ] ]
   or (last term is not needed, as well as the constants aren't)
parsed = [ C,  B[C+2] ]

this all, to improve the improved error / exception message even more ;-)


More information about the Python-list mailing list