Well, I believe the starting point would be to define the basic components of the expression.
When you look at a function and want to process it like that, it's basically a grammar, it can be a bit complicated depending on how much detail you want to allow.
Your grammar has the form of EXPRESSION.
EXPRESSION can be either:
TERM (where your function is basically something like nx^y)
or
TERM OPERATOR EXPRESSION
If you can parse a function like this, you simply need to define the rules for handling a TERM, and then recursively apply the same method for the rest of the expression.
Your polynomial will always have the form nx^y, with some simplifications for cases where y is 0 or 1, or when n is 1 and is omitted.
This is how I would approach it without using any additional libs. If you want, I can try and explain my point further.
By the way, I know my answer doesn't exactly address Python or the data structures to use, but it is one possible way of approaching this kind of problems.
answered 2012-06-22T11:40:39.377