Advertisement
go6odn28

8_word_encounter

Mar 25th, 2024
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.50 KB | None | 0 0
  1. import re
  2.  
  3.  
  4. filter_input = input()
  5. letter, needed_count = filter_input[0], int(filter_input[1])
  6. filtered_words = []
  7.  
  8. while True:
  9.     sentence = input()
  10.     if sentence == "end":
  11.         break
  12.  
  13.     if re.match(r'^[A-Z].*[.!?]$', sentence):
  14.         words = re.findall(r'\w+', sentence)
  15.         for word in words:
  16.             count = sum(1 for char in word if char == letter)
  17.             if count >= needed_count:
  18.                 filtered_words.append(word)
  19.  
  20.  
  21. print(", ".join(filtered_words))
  22.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement