Skip to content
Advertisement

How to split the integers and Operators characters from string in python?

I want to split the string into integers and operators for doing Infix expression evaluation in python.

Here is my string:

JavaScript

I tried this to split:

JavaScript

This is wrong. Since ’10’ is splitted into ‘1’,’0′

I tried alternative:

JavaScript

This is also went wrong. Since ‘)*’ should be splitted into ‘)’, ‘*’

Could you help to split the operators and integers from the given expression?

Advertisement

Answer

This is not the best solution for infix. Remove the + after [] like:

JavaScript

Try the following link for correct solution: Simple Balanced Parentheses

JavaScript

Keep in mind that this is a postfix implementation and its just for example. Do the infix by yourself and if you have any difficulties just ask.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement