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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started