def infix_to_postfix(expr):
    """
    infix convert to postfix
    :param expr: infix expression
    :return: postfix expression
    Example:
    >>> infix_to_postfix('(31+21)*33-31/17')
    31 21 + 33 * 31 17 / -
    """
    expr = spit_num(expr)
    stack = Stack()
    result_list = []
    for item in expr:
        if is_num(item):
            result_list.append(item)
        elif is_operator(item):
            while True:
                if stack.is_empty() or stack.peek() == '(' or cmp_priority(
                        item, stack.peek()):
                    stack.push(item)
                    break
                result_list.append(stack.pop())
        elif item == '(':
            stack.push(item)
        elif item == ')':
            while stack.peek() != '(':
                result_list.append(stack.pop())
            stack.pop()
        else:
            raise ValueError
    while not stack.is_empty():
        result_list.append(stack.pop())
    return ' '.join(result_list)
def infix_to_prefix(expr):
    expr = spit_num(expr)[::-1]
    stack = Stack()
    result_list = []
    for item in expr:
        if is_num(item):
            result_list.append(item)
        elif item == ')':
            stack.push(item)
        elif is_operator(item):
            if stack.is_empty() or stack.peek() == ')' or cmp_priority(
                    item, stack.peek()) > 0:
                stack.push(item)
            else:
                while True:
                    result_list.append(stack.pop())
                    if stack.is_empty() or stack.peek() == ')' or cmp_priority(
                            item, stack.peek()) > 0:
                        stack.push(item)
                        break
        else:
            while stack.peek() != ')':
                result_list.append(stack.pop())
            stack.pop()
    while not stack.is_empty():
        result_list.append(stack.pop())
    return ' '.join(result_list[::-1])