How to make a palindrome in python
You may have probably seen many solutions for checking whether a string is palindrome or not. But we are not going to see that again in here.
In this article, we will see how to make a palindrome from a string in Python.
def pal(s): l = len(s) p = s + s[-1-l%2 :: -1] return p print("A palindrome from 'malay' is ", pal('malay')) print("A palindrome from 'abc' is ", pal('abc'))
Output:
A palindrome from 'malay' is malayalam A palindrome from 'abc' is abcba
Subscribe
Login
Please login to comment
0 Discussion