Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- with open('./words.txt', 'r') as words_file:
- words = words_file.read().split(" ")
- unique_words = set(words)
- count = 0
- word_dict = {}
- total = 0
- for word in unique_words:
- if len(word) == 0:
- continue
- w_count = words.count(word)
- word_dict[word] = w_count
- total += w_count
- count += 1
- print('Number of unique words: %s' % count)
- for k in word_dict.keys():
- print('%s: %s occurances, %s percent of words' % (k, word_dict[k], round(word_dict[k] / total * 10000) / 100))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement