Την Τρίτη 22/02/2022 οι παλίνδρομες συμβολοσειρές είχαν την τιμητική τους.
Ας υποβάλλουμε λοιπόν τα σέβη μας :-)
#Classic
def is_palindrom(s):
n = len(s)
for i in range(n/2):
if s[i] != s[n-1-i]:
return False
return True
# One line scripts
def is_palindrom(s):
return s == s[::-1]
def is_palindrom(s):
return [True] * (len(s)/2) == [s[i] == s[len(s)-1-i] for i in range(len(s)/2)]
# Recursion
def is_palindrom(s):
if len(s) <=1:
return True
elif s[0] != s[len(s)-1]:
return False
else:
return is_palindrom(s[1:len(s)-1])
print is_palindrom('22022022')
print is_palindrom('anna')
print is_palindrom('niconanomimatamimonanocin')
print is_palindrom('nipsonanomimatamimonanopsin')