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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T05:59:57+00:00 2026-05-16T05:59:57+00:00

So here is my program with some new modifications: datafile = open(‘C:\\text2.txt’, ‘r’) completedataset

  • 0

So here is my program with some new modifications:

datafile = open('C:\\text2.txt', 'r')
completedataset = open('C:\\bigfile.txt', 'r')
smallerdataset = open('C:\\smallerdataset.txt', 'w')
matchedLines = []
for line in datafile:
    splitline = line.split()
    for item in splitline:
        if not item.endswith("NOVA"):
            if item.startswith("JJJ") or item.startswith("KOS"):
                matchedLines.append( item )
counter = 1
for line in completedataset:
    print counter
    counter +=1
    for t in matchedLines:
        if t in line:
            smallerdataset.write(line)
datafile.close()
completedataset.close()
smallerdataset.close()

The problem that I have now is that I want to search through the “bigfile” but at a faster rate. I would like to limit the searching of each line in bigfile to the string that occurs before the first ‘,’

I want to use something like index = aString.find(‘,’) I beleive but I’m not having much luck limiting the search of the big file to the string that occurs before the first comma.

  • 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-16T05:59:58+00:00Added an answer on May 16, 2026 at 5:59 am

    You could change

    if t in line:
    

    to

    if t in line[:line.find(',')]:
    

    This may make the program faster if line is very very long and the comma appears near the beginning. Or it may make the program slower if , appears near the end of the line.

    PS. Is every line guaranteed to have a comma in it? The above code acts a bit funky if there is no comma. For example,

    In [21]: line='a line of text'
    
    In [22]: line[:line.find(',')]
    Out[22]: 'a line of tex'
    

    If you want to ignore lines without a comma, this might be better:

    In [23]: line[:line.find(',')+1]
    Out[23]: ''
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to make some C++ program and I'm using function popen here to
Here's some code (full program follows later in the question): template <typename T> T
Here is some dprofpp -I output, for almost the same program on different input
So I've noticed some very weird behaviour from my program. Here's a simplified code
I'm very new to programming and for some reason this program is not calculating
I'm pretty new to android programming, but I've had some people program a widget
Here's a puzzle for you guys. I have a multithreaded program in which some
I am writing a Java program that inputs a test file, performs some modifications
I'm very new to Python and trying to write a program that parses some
Got a simple Javascript program here to accept and check a password. It should:

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.