Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6162753
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T21:42:26+00:00 2026-05-23T21:42:26+00:00

Task : Take two text files and output 100% matches and 75% matches. Solution

  • 0

Task: Take two text files and output 100% matches and 75% matches.

Solution:

import difflib
import csv

# Imports and parses the files
fileA = open("H:/comm.names.txt", 'r')
try:
        setA = fileA.readlines()
finally:    
        fileA.close()

fileB = open("H:/acad.names.txt", 'r')
try:
        setB = fileB.readlines()
finally:    
        fileB.close()

# 100% Match
setMatch100 = set(setA).intersection(setB)

Match100 = open("H:\Match100.txt", 'w')
try:
    for item in setMatch100:
        Match100.write(item)
finally:
    Match100.close()

# Remove 100% matches from the two lists
setA_LeftOver = set(setA).difference(setMatch100)
setB_LeftOver = set(setB).difference(setMatch100)

#Return the best match for setA_LeftOver[i] in setB_LeftOver that is at least 75% matching.
fMatch75 = open("H:\Match75.csv", 'w')
Match75 = csv.writer(fMatch75)
try:
    Match75.writerow(['File A', 'File B'])
    for item in setA_LeftOver:
                match = difflib.get_close_matches(item, setB_LeftOver, 1, 0.75)
                if len(match) > 0:
                        row = [item.rstrip(), match[0].rstrip()]
                        Match75.writerow(row)


finally:
    fMatch75.close()

Problem: This works, however the results aren’t very good. Here is an example of a match:

Fovea Pharmaceuticals SA Kobe Pharmaceutical Univ

I can’t turn up the minimum percent in Diff by too much because I need to be able to match Univ with University. Also, I can’t just make sure that the first words match because some strings start with “The” and need to be matched with strings that exclude “The”. Can anyone point me in a direction that would throw out matches that technically are 75% similar, but to a human aren’t similar at all?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T21:42:27+00:00Added an answer on May 23, 2026 at 9:42 pm

    I ended up writing a most common word script, and then I removed the most common words. This significantly improved my results as @e-satis suggested in his comment. However, difflib gave me better results than pylevenshtein so I can’t mark his answer as accepted.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Estimating how long any given task will take seems to be one of the
The task is to take a list of tables which is changeable. Write a
I am to take up the task of porting a C++ networking application code
A common task in programs I've been working on lately is modifying a text
I have the unfortunate task of having to import data from excel into a
Task: implement paging of database records suitable for different RDBMS. Method should work for
The task is simple, and the answers might be many. But here goes: On
Simple task like make AJAX request , pass one parameter and return result, can
Is there a rake task for backing up the data in your database? I
I've got the task of displaying a web form to represent the properties in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.