Advertisement
Guest User

Untitled

a guest
Jan 27th, 2020
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. def find_word(fname,word):
  2. count = 0
  3. index = ""
  4. i = 0
  5. with open(path+fname, "r", encoding='utf-8', errors='ignore') as file:
  6. text = file.read()
  7. words = text.split()
  8. while(i < len(text)):
  9. location = text.find(word,i)
  10. if(location != -1):
  11. index += ", " + str(location) + " "
  12. count += 1
  13. i += (location+len(word))
  14. file.close()
  15. print("Word count = %d words which are located at position " % count + str(index))
  16.  
  17. find_word("BestOfLove.txt","love")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement