Question: Python code! Write a function, palindromes, which takes a string as input and returns a list of the unique palindromes that appear in the input
Python code!
Write a function, palindromes, which takes a string as input and returns a list of the unique palindromes that appear in the input string. You may assume that the input string doesnt have any space characters and all characters are lowercase. The strings in the output should be sorted alphabetically. (Palindrome is a string that reads the same backward as forward, e.g., madam or kayak).
palindromes ('cabbbaccab') returns ['abbba', 'acca', 'baccab', 'bb', 'bbb', 'cabbbac', 'cc']
palindromes (' bacdcabdbacdc') returns ['abdba', 'acdca', 'bacdcab', 'bdb', 'cabdbac', 'cdc', 'cdcabdbacdc', 'dcabdbacd']
palindromes (' myracecars') returns ['aceca', 'cec', 'racecar']
You can start with the following code:
def palindromes(S): #write your code here
def testPalindromes (): #write your code here; see the sample test function on page#4
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
