with open('file.txt') as f:
words = f.read().split()
counts = dict()
for word in words:
counts[word] = counts.get(word, 0) + 1
sorted_asc = sorted(counts.items(), key=lambda x: x[1])
sorted_desc = sorted(counts.items(), key=lambda x: x[1], reverse=True)
print('word count:', len(words))
print('most frequent word :', sorted_desc[0])
print('least frequent word:', sorted_asc[0])
To embed this project on your website, copy the following code and paste it into your website's HTML: