True is a builtin but true in an undefined name
# Python program to reverse a string using stack# Function to create an empty stack.# It initializes size of stack as 0def createStack():stack=[]return stack# Function to determine the size of the stackdef size(stack):return len(stack)# Stack is empty if the size is 0def isEmpty(stack):if size(stack) == 0:return True# Function to add an item to stack .# It increases size by 1def push(stack,item):stack.append(item)#Function to remove an item from stack.# It decreases size by 1def pop(stack):if isEmpty(stack): returnreturn stack.pop()# A stack based function to reverse a stringdef reverse(string):n = len(string)# Create a empty stackstack = createStack()# Push all characters of string to stackfor i in range(0,n,1):push(stack,string[i])# Making the string empty since all#characters are saved in stackstring=""# Pop all characters of string and# put them back to stringfor i in range(0,n,1):string+=pop(stack)return string# Driver program to test above functionsstring="GeeksQuiz"string = reverse(string)print("Reversed string is " + string)# This code is contributed by Yash
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。