Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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