counts = dict()

with open('file.txt') as f:
    for word in f.read().split():
        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('most frequent word :', sorted_desc[0])
print('least frequent word:', sorted_asc[0])

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: