Palindrome stack | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Palindrome stack

https://code.sololearn.com/cNRe0HmTzL2n/?ref=app What is my error ? The output should be true ... And should work with .pop by how to become the result ?

26th Nov 2019, 11:00 AM
Sahra.P
Sahra.P - avatar
12 Answers
+ 2
You're using python, You can use stringname[::-1] to get whole string in reverse, why do you need to reverse it manually? simple solution is to compare text with text[::-1] def is_palindrome_stack(text): #Returns True if wird is a palindrome if text == text[::-1]: print (True) else: print (False) is_palindrome_stack('regallager')# True is_palindrome_stack('reliefpfeiler')#True
26th Nov 2019, 11:36 AM
Raj Chhatrala
Raj Chhatrala - avatar
+ 2
def is_palidrom(text) : arr = [] for c in text: arr. append(c) for c in text: if c !=arr.pop(): return False return True
27th Nov 2019, 1:58 PM
Stanislav
Stanislav - avatar
0
i need to do revetse it mannually because ir is my task 😒
26th Nov 2019, 12:00 PM
Sahra.P
Sahra.P - avatar
0
maybe you have a trick for me?
26th Nov 2019, 12:00 PM
Sahra.P
Sahra.P - avatar
0
First, you can inside of function make print of variable and you'll see - they are different. Short version, anyway : def is_palidrom(text) : return text == text[::-1] It will return True or False.
26th Nov 2019, 3:13 PM
Stanislav
Stanislav - avatar
0
but can i build the append and pop function to check the solution ?
26th Nov 2019, 8:16 PM
Sahra.P
Sahra.P - avatar
0
Sara. P you can. Can you say what is exactly your task?
27th Nov 2019, 1:18 PM
Stanislav
Stanislav - avatar
0
Write a function is_palindrome_stack (text) checks if the entered text is a palindrome. Use the solution for the stack function use (append / pop)
27th Nov 2019, 1:37 PM
Sahra.P
Sahra.P - avatar
0
i though about a for loop...? but i cant write a code 🤯
27th Nov 2019, 1:39 PM
Sahra.P
Sahra.P - avatar
0
thank you it works 😃
27th Nov 2019, 4:25 PM
Sahra.P
Sahra.P - avatar
0
thank you it works 😃
27th Nov 2019, 4:28 PM
Sahra.P
Sahra.P - avatar
0
You are welcome)
28th Nov 2019, 12:55 AM
Stanislav
Stanislav - avatar