I have written code to split a specific symbol out of a symbols list, but it is buggy and does not work properly. I hope someone can clarify and help me.
What I would like to do is to split this string (for example) - 'game.run();'
to this list of strings - ['game','.','run','(', ')',';']
where the Symbol list -
Symbollst = [
'{' , '}' , '(' , ')' , '[' , ']' , '.' ,
',' , ';' , '+' , '-' , '*' , '/' , '&' ,
',' , '<' , '>' , '=' , '~'
]
My initial code :
for token in r_splitted :
if any(x in token for x in Symbollst) :
TokenInSymbol = [i in token for i in Symbollst]
new_token = token.split(Symbollst[TokenInSymbol.index(True)])
new_token.insert(1,Symbollst[TokenInSymbol.index(True)])
for i in new_token :
if i=='' : continue
self.TokenList.append(i)
Note - this is part of Nand2Tetris compiler task.