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

后端 未结 4 1495
余生分开走
余生分开走 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:23

    You may get just alphanumeric character in your string;

    re.sub(r'[^a-zA-Z0-9]+', '', your_string).lower()
    

    By the way this one works, if you ignores non-ASCII chars.

提交回复
热议问题