Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for The Longest Palindromic by Mycroft0121
def longest_palindromic(a):
for l in range(len(a),0,-1):
for i in range(0, len(a)-l+1):
p = a[i:i+l]
if p ==p[::-1]:
return p
if __name__ == '__main__':
print("Example:")
print(longest_palindromic('abc'))
# These "asserts" are used for self-checking and not for an auto-testing
assert longest_palindromic('abc') == 'a'
assert longest_palindromic('abacada') == 'aba'
assert longest_palindromic('artrartrt') == 'rtrartr'
assert longest_palindromic('aaaaa') == 'aaaaa'
print("Coding complete? Click 'Check' to earn cool rewards!")
July 6, 2021