Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import collections
- import re
- def count_words_in_text(file_path):
- with open(file_path, 'r') as filehandle:
- text = filehandle.read().lower()
- word_list = re.sub('[-,."\n()]', ' ', text).split(' ')
- word_count = collections.Counter(word_list)
- for word, count in word_count.items():
- print(str(word) + ' (' + str(count)+')')
- count_words_in_text('text.txt')
Add Comment
Please, Sign In to add comment