I'm trying to write a process that splits a string into tokens. At the moment it looks like this:
separators = ['(', ')', '+', '-', '*', '/', '=']
def tokenize(string):
result_list = string.split()
print result_list
print tokenize('((2 + 3) / (4 * 22))')
Which outputs this:
['((2', '+', '3)', '/', '(4', '*', '22))']
Which is pretty close, but I need the parentheses split out from the string (i.e., the output above it should read:
['(', '(', '2', '+', '3', ')', '/', '(', '4', '*', '22', ')', ')']
Any thoughts or help? Thanks!