Advertisement
RedstoneHair

Untitled

Nov 19th, 2022
664
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.47 KB | None | 0 0
  1. strings = input().split(' ')
  2. search = input()
  3.  
  4. palindromes = [x for x in strings if x[::-1] == x]
  5. repeating = {}
  6.  
  7. for palindrome in palindromes:
  8.     if not palindrome in repeating.keys():
  9.         repeating[palindrome] = 0
  10.         continue
  11.     if repeating[palindrome] == 0:
  12.         repeating[palindrome] += 1
  13.     repeating[palindrome] += 1
  14.  
  15. print(palindromes)
  16.  
  17. times = max([0, *[v for k, v in repeating.items() if k == search]])
  18. print(f"Found palindrome {times} times")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement