Palindromes¶
A word or number is a palindrome if it reads the same backwards as forwards, such as the words madam or racecar, or the numbers 1234321 or 5680865. A single character word o single digit number are always palindromes.
Implement the following Python function in the palindromes module (file palindromes.py):
- gen_palindromes(L)¶
such that
given L, a list of words (
str)returns a list with all the palindrome words that can be obtained by concatenating any two words of L in the following terms for the resulting list:
It must not contain repetitions.
It must not contain words resulting from concatenating a word with itself.
It can have the correct words in any order.
Bear in mind that the order of concatenation is important since a different order may produce a different word.
For example:
>>> l = ['ab', 'a', 'ba']
>>> lcorr = ['aba', 'abba', 'baab']
Doctests are available at the file gen_palindromes-test.txt.