4. To write a python program to find the most frequent words in a text file.
from collections import Counter
# Read in the text file
with open('text_file.txt', 'r') as file:
text = file.read()
# Split the text into individual words and count their occurrences
word_counts = Counter(text.split())
# Get the 10 most common words
most_common_words = word_counts.most_common(10)
# Print the results
for word, count in most_common_words:
print(word, count)