...

/

Challenge: Prefix to Postfix Conversion

Challenge: Prefix to Postfix Conversion

Convert a prefix expression to a postfix expression.

Problem statement

In this challenge, write a function postfix(prefix) that takes a prefix expression as prefix, converts it to a postfix expression using a stack, and then returns it.

  • Prefix expression: An expression in which the operator appears before the operands.

  • Postfix expression: An expression in which the operator appears after the operands.

For example, if we have an expression A+BA+B, then its prefix expression would be +AB+AB, and its postfix expression would be AB+AB+.

Input

A prefix expression in the form of a string.

Output

A postfix expression in the form of a string.

Sample input

'+AB'

Sample output

'AB+'

Try to implement the function below. Don’t forget to use the concepts taught in the previous lessons. Feel free to view the solution, after giving it a few shots. Good luck!

Press + to interact
from collections import deque
def postfix(prefix):
stack = deque()
# Begin writing your implementation here
pass

We hope that you were able to solve the challenge.


Ask