Skip to content

Instantly share code, notes, and snippets.

@vatsalparekh
Created February 8, 2018 20:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vatsalparekh/0e76f01bd9e2186130d1042f1f0390b9 to your computer and use it in GitHub Desktop.
Save vatsalparekh/0e76f01bd9e2186130d1042f1f0390b9 to your computer and use it in GitHub Desktop.
word count
input_file = open('hello.txt','r')
input_text = input_file.readlines()
total_words = sum([len(line.split()) for line in input_text])
all_words = [word for word in line.split() for line in input_text]
all_unique_words = set(all_words)
occurence = {word:all_words.count(word) for word in all_unique_words}
print occurence
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment