1

Hello I'm new coding and I have one doubt about a problem that ask me to compare an input string and define if is a palindrome or not. I've read about some answers but I'm not sure why they use some parts. In this code:

def is_palindrome(input_string):
    ns = ""
    rv = ""
    input_string =input_string.lower()

    for x in input_string:
        **if x!=" ":**
        ns =ns+ x
        rs = x+rs
    # Compare the strings
    if ns==rs:
        return True
    return False

The part of the code that is if x!=" ": is the part I don't get it. I understand that the for loop allow us to place us in each letter of the input script but if it's a space the character in the script what happen?

Tolgahan ÜZÜN
  • 423
  • 7
  • 14
  • 1
    This means if the value of X isnt a space or “ “ – Evorage Jul 13 '20 at 22:02
  • ... *They* must have had a specification that excluded spaces when evaluating palindromeness - the spaces don't count in their definition of a palindrome. – wwii Jul 13 '20 at 22:06
  • Does this answer your question? [Is there a "not equal" operator in Python?](https://stackoverflow.com/questions/11060506/is-there-a-not-equal-operator-in-python) – Craig Jul 13 '20 at 22:10
  • Ok, I get it now. We're just evaluating if the string is Palindrome and we're not including the space. Thanks!!!! – Glamerstone Jul 13 '20 at 22:11

0 Answers0