Skip to content

Instantly share code, notes, and snippets.

@bha159
Created February 5, 2018 00:35
Show Gist options
  • Save bha159/f4a94b85b96880608118dbdcb32de63d to your computer and use it in GitHub Desktop.
Save bha159/f4a94b85b96880608118dbdcb32de63d to your computer and use it in GitHub Desktop.
A python program to calculate occurence of a word in a text file.
word=input("Enter a word\n")
handle=open("my_data.txt")
data=handle.read().split(" ")
d=dict()
for i in data:
if i in d:
d[i]+=1
else:
d[i]=1
print("Occurence",d[word])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment