# Python - Reverse Polish Notation [duplicate]

Possible Duplicate:
Reverse Polish notation

Create a function named rpn in python to evaluate a string written in Reverse Polish notation

Numbers must be separated by one or more spaces; operators do not need to be separated by spaces. Must support +, -, * and /.

Return can be any type that int() will accept

Eval is allowed.

Examples:

>>> 3 7 +
10

>>> 1 2+3*4-
5

• why only python? many languages are good for this – ratchet freak Dec 20 '11 at 21:24
• Should a different character (such as _) be used to represent negative numbers? In your current specification, does 2 3 -7 * mean 2 * 3 * -7 or (2 - 3) * 7? – Dillon Cower Dec 20 '11 at 21:28
• ratchet -- I'm just interested in seeing the interesting solutions people come up with in python, rather than extending the challenge to all languages and having only 1 or 2 python solutions. – bluepnume Dec 20 '11 at 21:37
• D C -- Good point, I've simplified the problem to remove the requirement for negative numbers. – bluepnume Dec 20 '11 at 21:38
• It is almost the same task as Reverse Polish notation. There are also some answers written in Python. – Howard Dec 20 '11 at 21:49