Can I make a code in python that ignores special characters such as commas, spaces, exclamation points, etc?

后端 未结 4 1582
余生分开走
余生分开走 2021-01-23 11:39

I want to create a code that will return \"true\" (if I type in a palindrome regardless of case or if there are special characters in it), and \"false\" otherwise. The code I ha

4条回答
  •  遇见更好的自我
    2021-01-23 12:34

    my_str = my_str.casefold()
    my_str = ''.join(e for e in my_str if e.isalpha())
    

    This should recreate my_str with only alphabetical characters, using .isalpha(). Then do the test on that. If you want to keep a record of original string, just stored the recreated version is a temporary string.

提交回复
热议问题