Guest User

Untitled

a guest
Aug 19th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. Palindrome Python Program - Homework
  2. '''
  3. palindrome(T) is True if T is the same as
  4. the backwards version of T, and otherwise
  5. is False.
  6.  
  7. palindromes(L) returns a list of the palindromes in L
  8.  
  9. >>> palindrome("madam")
  10. True
  11. >>> palindrome([6,9,6])
  12. True
  13. >>> palindrome("T r ")
  14. False
  15. >>> palindromes( [ [1], [3,2], [5,1,5], [0,0,1], [7,3,7,3] ] )
  16. [[1], [5, 1, 5]]
  17. >>> palindromes( "son daughter dad mom ewe any".split() )
  18. ['dad', 'mom', 'ewe']
  19. >>> palindromes( "stressed desserts stop pots live evil".split() )
  20. []
  21. >>> palindromes( ["stressed desserts", "stop pots", "can can", "too few"] )
  22. ['stressed desserts', 'stop pots']
  23. '''
  24.  
  25. if __name__ == "__main__":
  26. import doctest
  27. doctest.testmod()
  28.  
  29. def palindrome(L):
  30. if L == L[::-1]:
  31. return True
  32. else:
  33. return False
  34.  
  35. def palindromes(L):
  36. return filter(palindrome ,range(6))
  37.  
  38. def palindromes(L):
  39. return filter(palindrome ,L)
  40.  
  41. def palindrome(L):
  42. return L == L[::-1]
Add Comment
Please, Sign In to add comment