AyanUpadhaya

Find numbers of specific word from a text file

Apr 11th, 2021 (edited)
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.23 KB | None | 0 0
  1. import re
  2.  
  3. word='Lorem Ipsum'
  4. findword=re.compile(f'{word}')
  5.  
  6. with open('mytext.txt','r') as file:
  7.     data=file.read()
  8.     wl=findword.search(data)
  9.     l=wl.group()
  10.     print('{} has been founded {} times'.format(word,data.count(l)))
  11.    
Add Comment
Please, Sign In to add comment