Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def find_word(fname,word):
- count = 0
- index = ""
- i = 0
- with open(path+fname, "r", encoding='utf-8', errors='ignore') as file:
- text = file.read()
- words = text.split()
- while(i < len(text)):
- location = text.find(word,i)
- if(location != -1):
- index += ", " + str(location) + " "
- count += 1
- i += (location+len(word))
- file.close()
- print("Word count = %d words which are located at position " % count + str(index))
- find_word("BestOfLove.txt","love")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement