Skip to content

Commit 629b914

Browse files
Update String_Palindrome.py
more efficient
1 parent 7a67509 commit 629b914

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

String_Palindrome.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
# Program to check if a string is palindrome or not
22

3-
my_str = 'aIbohPhoBiA'
3+
my_str = input().strip()
44

55
# make it suitable for caseless comparison
66
my_str = my_str.casefold()
77

88
# reverse the string
9-
rev_str = reversed(my_str)
9+
rev_str = my_str[::-1]
1010

1111
# check if the string is equal to its reverse
12-
if list(my_str) == list(rev_str):
12+
if my_str == rev_str:
1313
print("The string is a palindrome.")
1414
else:
1515
print("The string is not a palindrome.")

0 commit comments

Comments
 (0)