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 6165025
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T22:05:38+00:00 2026-05-23T22:05:38+00:00

I am working with a very large text file (500MB+) and the code I

  • 0

I am working with a very large text file (500MB+) and the code I have is outputting perfectly but I am getting a lot of duplicates. What I am looking to do is check the output file to see if the output exists before it writes to the file. I am sure it is just one line in an if statement, but I do not know python well and cannot figure out the syntax. Any help would be greatly appreciated.

Here is the code:

authorList = ['Shakes.','Scott']

with open('/Users/Adam/Desktop/Poetrylist.txt','w') as output_file:
    with open('/Users/Adam/Desktop/2e.txt','r') as open_file:
            the_whole_file = open_file.read()
            for x in authorList:
                start_position = 0 
                while True:
                   start_position = the_whole_file.find('<A>'+x+'</A>', start_position)
                   if start_position < 0:
                       break
                   end_position = the_whole_file.find('</W>', start_position)
                   output_file.write(the_whole_file[start_position:end_position+4])
                   output_file.write("\n")    
                   start_position = end_position + 4
  • 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-23T22:05:39+00:00Added an answer on May 23, 2026 at 10:05 pm

    I suggest that you simply keep track of which author data you have already seen, and only write it if you haven’t seen it before. You can use a dict to keep track.

    authorList = ['Shakes.','Scott']
    already_seen = {} # dict to keep track of what has been seen
    
    with open('/Users/Adam/Desktop/Poetrylist.txt','w') as output_file:
        with open('/Users/Adam/Desktop/2e.txt','r') as open_file:
                the_whole_file = open_file.read()
                for x in authorList:
                    start_position = 0 
                    while True:
                       start_position = the_whole_file.find('<A>'+x+'</A>', start_position)
                       if start_position < 0:
                           break
                       end_position = the_whole_file.find('</W>', start_position)
                       author_data = the_whole_file[start_position:end_position+4]
                       if author_data not in already_seen:
                           output_file.write(author_data + "\n")
                           already_seen[author_data] = True
                       start_position = end_position + 4
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working with a very large (~11GB) text file on a Linux system.
I'm working on a project which generates a very large number of sequential text
I'm working on a very large project with three phases of source code. Development
I have recently started working on a very large C++ project that, after completing
I'm working with a very big text file (755Mb). I need to sort the
I have a very irritating problem. I'm working with a list of documents, but
I have a very old, very very large, fully working, C program which plays
I'm working on a very large, data-intensive legacy application. Both the code base &
I am working on sorting several large files in C++. I have a text
As part of my work, I am working with very large text files and,

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.