0
Hello I'm trying to write a program that check if a sentence is a palindrome.. But it's not working ...
How do i let the computer ignore spaces and commas between a sentence so it can check if a sentence is a palindrome..e.g...dennis and edna sinned... Mind you i'm using python ans you can check out the code below https://code.sololearn.com/cN5X5yyOOQ9U/?ref=app
9 odpowiedzi
+ 9
Use replace () to replace spaces and commas with empty string
https://www.google.co.in/amp/s/www.geeksforgeeks.org/JUMP_LINK__&&__python__&&__JUMP_LINK-string-replace/amp/
+ 8
+ 3
tobi emma Oladele try this code.
It's ignore spaces and even special characters.
https://code.sololearn.com/cjMKl86EVJpt/?ref=app
+ 3
tobi emma Oladele you can also do this in just one line.
m=''.join([i for i in x if i.isalpha() or i.isdigit()])
x=m
+ 1
Maninder singh
0
Rstar ,is there no method i can use without using replace function
0
Maninder $ingh ,,it's working for words,numbers .the problem is when i want to check if a sentence such as dennis and edna sinned...it's not working...any idea
0
if str.replace(' ', '') == str.replace(' ', '')[::-1]: ...
0
Maninder $ingh thanks so much for that insight...i've just modified...i added isnumeric() to the codes to accomodate numbers...i'm grateful..