Write a function revstring(mystr) that uses a stack to reverse the characters in a string. Save & RunShow FeedbackShow CodetestEqual(revstring('1234567890'),'0987654321') 1from test import testEqual2from pythonds.basic import Stack34def revstring(mystr):5 # your code here67testEqual(revstring('apple'),'elppa')8testEqual(revstring('x'),'x')9testEqual(revstring('1234567890'),'0987654321')10
def revstring(s): sta = Stack() for i in range(0, len(s)): sta.push(s[i])
outputstr = ''
while not sta.isempty():
outputstr = outputstr + sta.pop()
return outputstr