Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. автозапчасти лексус новосибирск
  2. автозапчасти лексус в туле
  3. запчасти для lexus ls 460
  4. разборка lexus rx
  5. запчасти на лексус rx 330 бу
  6. разборка lexus rx
  7.  
  8. file ='C:\words.txt'
  9.  
  10. uniqlines = set(open(file,'r', encoding='utf-8').readlines())
  11. gotovo = open(file,'w', encoding='utf-8').writelines(set(uniqlines))
  12.  
  13. #!/usr/bin/env python3
  14. import sys
  15. import fileinput
  16.  
  17. with fileinput.FileInput(inplace=True, backup='.bak', mode='rb') as file:
  18. seen = set()
  19. for line in file:
  20. if line not in seen: # first time
  21. seen.add(line)
  22. sys.stdout.buffer.write(line) # redirected to the file
  23.  
  24. T:> python remove-duplicates-inplace.py C:words.txt
  25.  
  26. for line in file:
  27. words = tuple(line.split())
  28. if words not in seen:
  29. seen.add(words)
  30. sys.stdout.buffer.write(line)
  31.  
  32. #!/usr/bin/env python3
  33. from collections import OrderedDict
  34.  
  35. filename = r'C:words.txt'
  36. with open(filename, encoding='utf-8') as file:
  37. uniq = OrderedDict.fromkeys(file)
  38. with open(filename, 'w', encoding='utf-8') as file:
  39. file.writelines(uniq)
  40.  
  41. def delete_string():
  42. File = open('test.txt', 'r')
  43. str_list = []
  44. for i in File.readlines():
  45. if i not in str_list:
  46. str_list.append(i)
  47. File.close()
  48. File = open(a, 'w')
  49. for j in str_list:
  50. File.write(j)
  51.  
  52. from tempfile import mkstemp
  53. from os import close, remove
  54. from shutil import move
  55.  
  56. def write_lines(file='words.txt'):
  57. ft, temp = mkstemp()
  58. lines = []
  59. with open(temp, 'w') as t, open(file) as f:
  60. for line in f:
  61. if line not in lines:
  62. lines.append(line)
  63. t.write(line)
  64. close(ft)
  65. remove(file)
  66. move(temp, file)
  67. write_lines()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement