for word in file.read().split():
    if word not in wordcount:
        wordcount[word] = 1
else:
    wordcount[word] += 1
for key in list(wordcount.keys()):
    print('%s %s ' % (key, wordcount[key]))
file.close()
подсчет слов python из программы txt file