Advertisement
BdW44222

03. Find Occurrences of Word in Sentence

Aug 12th, 2021
1,608
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.26 KB | None | 0 0
  1. import re
  2. string_input = input()
  3. occurrences = input()
  4. occurrences_count = []
  5.  
  6. pattern = f"\\b{occurrences}\\b"
  7.  
  8. matches = re.findall(pattern, string_input, re.IGNORECASE)
  9.  
  10. if matches:
  11.     occurrences_count.extend(matches)
  12.  
  13. print(len(occurrences_count))
  14.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement