Задача: Поиск дубликатов внутри файла
Исходник: Поиск и печать повторяющихся строк в файле, язык: python [code #583, hits: 17335]
автор: - [добавлен: 28.01.2009]
  1. import os
  2.  
  3. ## Move into the directory where the database is.
  4. os.chdir('folder where file is')
  5.  
  6. open_file = open('candidates.txt', 'r')
  7. line = open_file.readline()
  8. name = line.strip()
  9.  
  10. candidateDict = {}
  11.  
  12. def find_duplicate():
  13. for name in open_file:
  14. if candidateDict.has_key(name):
  15. candidateDict[name] += 1
  16. else:
  17. candidateDict[name] = 1
  18.  
  19. find_duplicate()
  20.  
  21. for name in candidateDict:
  22. if candidateDict[name] > 1:
  23. print name
  24.  
  25. open_file.close()

+добавить реализацию