Challenge: Prefix to Postfix Conversion
Convert a prefix expression to a postfix expression.
We'll cover the following...
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 , then its prefix expression would be , and its postfix expression would be .
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!
from collections import dequedef postfix(prefix):stack = deque()# Begin writing your implementation herepass
We hope that you were able to solve the challenge.