> <snark>Besides, the point isn't the shortest code but to illustrate the idea > of handling special syntax.</snark>
In my defense, I was typing on my phone while watching a show on Netflix. I was hardly in a position to test any code. :-) As you indicated though, the problem is under-specified (nesting?, presence of quotation marks?, newlines between balanced parens? input size?, etc). It probably does little good to try and cook up a comprehensive solution to such a problem. Better to just toss out some ideas for the OP and let them mull it over, maybe try to solve the problem themselves. Skip -- https://mail.python.org/mailman/listinfo/python-list