Python - Reverse Polish Notation

0

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

bluepnume

Posted 2011-12-20T21:11:06.387

Reputation: 143

Question was closed 2011-12-21T09:46:32.017

1why only python? many languages are good for this – ratchet freak – 2011-12-20T21:24:16.640

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 – 2011-12-20T21:28:07.093

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 – 2011-12-20T21:37:52.823

D C -- Good point, I've simplified the problem to remove the requirement for negative numbers. – bluepnume – 2011-12-20T21:38:27.627

6

It is almost the same task as Reverse Polish notation. There are also some answers written in Python.

– Howard – 2011-12-20T21:49:46.740

No answers