start = int(input("Начало(например 100001): ")) end = int(input("Конец(например 999999): ")) words_file = input("Словарь: ") output_file = input("Сохранить: ") def read_words(filename): for enc in ("utf-8", "cp1251", "latin-1"): try: with open(filename, "r", encoding=enc) as f: return [line.strip() for line in f if line.strip()] except UnicodeDecodeError: continue raise Exception("ERROR") words = read_words(words_file) with open(output_file, "w", encoding="utf-8") as out: buffer = [] for number in range(start, end + 1): for word in words: line = f"{number};{word}" print(line) buffer.append(line + "\n") if len(buffer) > 10000: out.writelines(buffer) buffer = [] if buffer: out.writelines(buffer) print("Готово!")