Python: re
import re from collections import defaultdict regex = re.compile(r'[^\w-]+') valor = defaultdict(lambda: 0) with open(file = 'statistic.txt', mode = 'r+t', encoding = 'utf8', errors = 'strict', newline = None) as f: for line in f: for word in regex.split(line): if word and not word.isdigit(): valor[word.lower()] += 1 valor = sorted(valor.items(), key = lambda item: item[1], reverse = True) print(valor)