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

30th Nov 2018, 4:46 PM
tobi emma Oladele
tobi emma Oladele - avatar
9 ответов
30th Nov 2018, 4:51 PM
Rstar
Rstar - avatar
30th Nov 2018, 4:58 PM
Rstar
Rstar - avatar
+ 3
tobi emma Oladele try this code. It's ignore spaces and even special characters. https://code.sololearn.com/cjMKl86EVJpt/?ref=app
30th Nov 2018, 5:09 PM
Maninder $ingh
Maninder $ingh - avatar
+ 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
1st Dec 2018, 2:36 AM
Maninder $ingh
Maninder $ingh - avatar
+ 1
Maninder singh
1st Dec 2018, 2:45 AM
tobi emma Oladele
tobi emma Oladele - avatar
0
Rstar ,is there no method i can use without using replace function
30th Nov 2018, 4:56 PM
tobi emma Oladele
tobi emma Oladele - avatar
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
30th Nov 2018, 5:00 PM
tobi emma Oladele
tobi emma Oladele - avatar
0
if str.replace(' ', '') == str.replace(' ', '')[::-1]: ...
30th Nov 2018, 5:41 PM
HonFu
HonFu - avatar
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..
1st Dec 2018, 1:51 AM
tobi emma Oladele
tobi emma Oladele - avatar