Construct a function that, when given a string containing an expression in infix notation, will return an identical expression in postfix notation.
The operators used will be `+`, `-`, `*`, `/`, and `^` with standard precedence rules and left-associativity of all operators but `^`.
The operands will be single-digit integers between 0 and 9, inclusive.
Parentheses may be included in the input, and are guaranteed to be in correct pairs.
```javascript 
toPostfix("2+7*5"); // Should return "275*+"
toPostfix("3*3/(7+1)"); // Should return "33*71+/"
toPostfix("5+(6-2)*9+3^(7-1)"); // Should return "562-9*+371-^+"
```
```python
to_postfix("2+7*5") # Should return "275*+"
to_postfix("3*3/(7+1)") # Should return "33*71+/"
to_postfix("5+(6-2)*9+3^(7-1)") # Should return "562-9*+371-^+"
```
You may read more about postfix notation, also called Reverse Polish notation, here:
http://en.wikipedia.org/wiki/Reverse_Polish_notation
operand = set("0123456789")
operator = {'+':1, '-':1, '*':2, '/':2, '^':3}

def to_postfix (infix):
    stack, res = [], []
    for c in "({})".format(infix):
        if c in operand:
            res.append(c)
        elif c == '(':
            stack.append(c)
        elif c == ')':
            while stack[-1] != '(':
                res.append(stack.pop())
            del stack[-1]
        elif c in operator:
            while operator.get(stack[-1], 0) >= operator[c]:
                res.append(stack.pop())
            stack.append(c)
        else:
            raise Exception("Character {} unknown".format(c))
    return ''.join(res)
operand = set("0123456789")
operator = {'+':1, '-':1, '*':2, '/':2, '^':3}

def to_postfix (infix):
    stack, res = [], []
    for c in "({})".format(infix):
        if c in operand:
            res.append(c)
        elif c == '(':
            stack.append(c)
        elif c == ')':
            while stack[-1] != '(':
                res.append(stack.pop())
            del stack[-1]
        elif c in operator:
            while operator.get(stack[-1], 0) >= operator[c]:
                res.append(stack.pop())
            stack.append(c)
        else:
            raise Exception("Character {} unknown".format(c))
    return ''.join(res)