palindrome
2024. 11. 28. 15:38ㆍ정보처리,전산/Python
반응형
def ispal(s):
s = s.lower().replace(" ", "") # Remove spaces and convert to lowercase
return s == s[::-1] # Check if the string is a palindrome
s = "A man a plan a canal Panama" # Updated input data
print(ispal(s)) # Output the palindrome check result
Output:
True
The result is True because "A man a plan a canal Panama" is a palindrome when spaces and case are ignored.
반응형
'정보처리,전산 > Python' 카테고리의 다른 글
float("inf") 무한대 객체 (0) | 2025.01.13 |
---|---|
Actual, Formal Parameter (1) | 2024.12.01 |
데이터 타입을 처리, 결과를 누적 (0) | 2024.11.28 |
재귀와 메모이제이션을 활용한 수열 계산 (0) | 2024.11.28 |
Class 에서 init self 사용 (0) | 2024.11.14 |