Advertisement
DiYane

Palindrome Strings

Sep 20th, 2023
525
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.38 KB | None | 0 0
  1. def is_palindrome(word):
  2.     return word == word[::-1]
  3.  
  4. sequence = input().split()
  5. palindrome_to_find = input()
  6.  
  7. found_palindromes = []
  8.  
  9. for word in sequence:
  10.     if is_palindrome(word):
  11.         found_palindromes.append(word)
  12.  
  13. print(found_palindromes)
  14.  
  15. palindrome_count = found_palindromes.count(palindrome_to_find)
  16.  
  17. print(f'Found palindrome {palindrome_count} times')
Tags: python
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement