Over a million developers have joined DZone.

Duplicate Finder In Text File

·
// 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
        else:
            candidateDict[name] = 1

find_duplicate()

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

open_file.close()

Topics:

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

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

{{ parent.tldr }}

{{ parent.urlSource.name }}