Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import time
- print('Все тестовые файлы находятся в папке Examples')
- inp = input('укажите название файла с типом(.txt):\n')
- text = open(r'C:\projects\deletestring\examples\''[:-1] + inp, 'r', encoding='utf-8')
- start_time = time.time()
- line = [line.strip() for line in text]
- unique = []
- [unique.append(item) for item in line if item not in unique]
- if not unique:
- print('\nДубликаты удалены.')
- text.close()
- print("---Выполнено за %s секунд ---" % (time.time() - start_time))
- # Создание копии
- exp = input(
- 'Укажите название и расширение для сохранения ред. копии файла (файл сохранится в папке result)\n'
- 'или нажмите Enter, чтобы вывести результат в консоль:\n')
- if exp and not exp.isspace():
- red = open(r'C:\projects\deletestring\result\''[:-1] + exp, 'w')
- # Запись уникальных строк в файл
- for index in unique:
- red.write(index + '\n')
- red.close()
- else:
- for index in unique:
- print(index + '\n')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement