Created
February 8, 2018 20:14
-
-
Save vatsalparekh/0e76f01bd9e2186130d1042f1f0390b9 to your computer and use it in GitHub Desktop.
word count
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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