Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Palindrome Python Program - Homework
- '''
- palindrome(T) is True if T is the same as
- the backwards version of T, and otherwise
- is False.
- palindromes(L) returns a list of the palindromes in L
- >>> palindrome("madam")
- True
- >>> palindrome([6,9,6])
- True
- >>> palindrome("T r ")
- False
- >>> palindromes( [ [1], [3,2], [5,1,5], [0,0,1], [7,3,7,3] ] )
- [[1], [5, 1, 5]]
- >>> palindromes( "son daughter dad mom ewe any".split() )
- ['dad', 'mom', 'ewe']
- >>> palindromes( "stressed desserts stop pots live evil".split() )
- []
- >>> palindromes( ["stressed desserts", "stop pots", "can can", "too few"] )
- ['stressed desserts', 'stop pots']
- '''
- if __name__ == "__main__":
- import doctest
- doctest.testmod()
- def palindrome(L):
- if L == L[::-1]:
- return True
- else:
- return False
- def palindromes(L):
- return filter(palindrome ,range(6))
- def palindromes(L):
- return filter(palindrome ,L)
- def palindrome(L):
- return L == L[::-1]
Add Comment
Please, Sign In to add comment