Advertisement
MAN5ON

OldCode

Oct 14th, 2020
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.18 KB | None | 0 0
  1. import time
  2.  
  3. print('Все тестовые файлы находятся в папке Examples')
  4. inp = input('укажите название файла с типом(.txt):\n')
  5. text = open(r'C:\projects\deletestring\examples\''[:-1] + inp, 'r', encoding='utf-8')
  6. start_time = time.time()
  7. line = [line.strip() for line in text]
  8. unique = []
  9. [unique.append(item) for item in line if item not in unique]
  10. if not unique:
  11.     print('\nДубликаты удалены.')
  12. text.close()
  13. print("---Выполнено за %s секунд ---" % (time.time() - start_time))
  14. # Создание копии
  15. exp = input(
  16.     'Укажите название и расширение для сохранения ред. копии файла (файл сохранится в папке result)\n'
  17.     'или нажмите Enter, чтобы вывести результат в консоль:\n')
  18. if exp and not exp.isspace():
  19.     red = open(r'C:\projects\deletestring\result\''[:-1] + exp, 'w')
  20.     # Запись уникальных строк в файл
  21.     for index in unique:
  22.         red.write(index + '\n')
  23.     red.close()
  24.  
  25. else:
  26.     for index in unique:
  27.         print(index + '\n')
  28.  
  29.  
  30.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement