Over a million developers have joined DZone.

Duplicate Finder In Text File

DZone's Guide to

Duplicate Finder In Text File

Free Resource
// Searches for and prints duplicates within a text file.

import os

## Move into the directory where the database is.
os.chdir('folder where file is')

open_file = open('candidates.txt', 'r')
line = open_file.readline()
name = line.strip()

candidateDict = {}

def find_duplicate():
    for name in open_file:
        if candidateDict.has_key(name):
            candidateDict[name] += 1
            candidateDict[name] = 1


for name in candidateDict:
    if candidateDict[name] > 1:
        print name



Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}