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

  • SEARCH
  • Home
  • 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 6593129
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:38:33+00:00 2026-05-25T17:38:33+00:00

I have two text files, file1 and file2 . File1 contains a bunch of

  • 0

I have two text files, file1 and file2.

File1 contains a bunch of random words, and file2 contains words that I want to remove from file1 when they occur.
Is there a way of doing this?

I know I probably should include my own attempt at a script, to at least show effort, but to be honest it’s laughable and wouldn’t be of any help.

If someone could at least give a tip about where to start, it would be greatly appreciated.

  • 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-25T17:38:33+00:00Added an answer on May 25, 2026 at 5:38 pm

    get the words from each:

    f1 = open("/path/to/file1", "r") 
    f2 = open("/path/to/file2", "r") 
    
    file1_raw = f1.read()
    file2_raw = f2.read()
    
    file1_words = file1_raw.split()
    file2_words = file2_raw.split()
    

    if you want unique words from file1 that aren’t in file2:

    result = set(file1_words).difference(set(file2_words))
    

    if you care about removing the words from the text of file1

    for w in file2_words:
        file1_raw = file1_raw.replace(w, "")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two very large(30000+ documents) collections, one contains words extracted from a text
So I have two files, one that contains my text, and another which I
I have two text files that contain columnar data of the variety position -
I have two text files, I want to place a text in the middle
I have two large (~100 GB) text files that must be iterated through simultaneously.
I have a text file that contains a bunch of sentences. The sentences contain
I have a bunch of PDF files that came from scanned documents. The files
I have about 150 text files filled with character information. Each file contains two
I have a text file words.txt that contains english words. Let's assume it contains
I have two text files bala.txt and bala1.txt bala.txt contains text line by line

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.