Функция StringChallenge(strParam) принимает на вход строку и определяет, является ли она палиндромом, игнорируя знаки препинания и символы. Верните true, если это палиндром, в противном случае верните false.
def StringChallenge(strParam):
"""
Checks if a string is a palindrome, ignoring punctuation and symbols.
Args:
strParam: The input string.
Returns:
True if the string is a palindrome, False otherwise.
"""
# Remove non-alphanumeric characters and convert to lowercase
cleaned_str = ''.join(c for c in strParam if c.isalnum()).lower()
# Check if the cleaned string is a palindrome
return cleaned_str == cleaned_str[::-1]
def StringChallenge(strParam):
"""
Checks if a string is a palindrome, ignoring punctuation and symbols.
Args:
strParam: The input string.
Returns:
True if the string is a palindrome, False otherwise.
"""
# Remove non-alphanumeric characters and convert to lowercase
cleaned_str = ''.join(c for c in strParam if c.isalnum()).lower()
# Check if the cleaned string is a palindrome
return cleaned_str == cleaned_str[::-1]
Подробнее здесь: https://stackoverflow.com/questions/791 ... and-symbol
Палиндром игнорирует знаки препинания и символы ⇐ Python
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение