# Online Python compiler (interpreter) to run Python online.
# Write Python 3 code in this online editor and run it.
import re
from collections import Counter
def analyze_text(file_path):
with open(file_path, 'r', encoding='utf-8') as f:
text = f.read().lower()
words = re.findall(r'\b\w+\b', text)
total_words = len(words)
most_common = Counter(words).most_common(10)
print(f'Total words: {total_words}')
print('Top 10 frequent words:')
for word, count in most_common:
print(f'{word}: {count}')
# Example usage
# analyze_text('sample.txt')