Thank you for your corrections to the previous code. Your regex solution is definitely much cleaner. Referring to your other suggestions, is the advantage of using a list of chars instead of adding to a string just a bow to big-O complexity, or are there other considerations? First I had tried appending to the string, but it seems they are immutable. It seems that using a list for a string isn't a very clear way to represent a mutable string.
Although I gladly accept that using a regex is the best solution to this problem, I am still interested in knowing how to access the variables in a containing function. It seems that there should be some keyword akin to global that would expose them, or some other method. I have read that python uses nested scopes (or at least was planning to in 2.2), so I wonder what I am missing. -- http://mail.python.org/mailman/listinfo/python-list