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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T19:06:01+00:00 2026-05-31T19:06:01+00:00

I am writing a code which compares file1 (single column of entries) with file

  • 0

I am writing a code which compares file1 (single column of entries) with file 2 (3 column of entries) and fetch matched records from file 2 on basis of first column. The problem is that it is evaluating the loop only once.

File1:

ABC

DEF

JKL

File2:

IJK,123,SDF

ABC,456,HJK

QWE,876,GFT

JKL,098,HGF

…..

My code:

for entry in fh_file1:
    mir = entry.strip('\n')
    print(mir)
    for row in fh_file2:
        row_splt = row.split(',')             
        print(row_splt[0])
        if mir in row_splt[0]:
            print (row.strip('\n'))
        else:
            pass

Result from that code:

is just the match of first entry of file 1:

ABC 456 HJK

Please help me on this.

  • 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-31T19:06:03+00:00Added an answer on May 31, 2026 at 7:06 pm

    You need to add fh_file2.seek(0) before the second for loop to start over at the beginning of the file.

    You’d be better served, however, by reading it into memory once:

    file2_lines = fh.file2.readlines()
    

    then iterating over file2_lines. Reading the file from disk for each line in another file is going to be very slow.

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

Sidebar

Related Questions

I'm writing some code which involves running a few shell commands from Python and
I am writing some code in which i need to get a line from
I'm writing code to download email from various servers, some of which are outside
I am writing a code in JDK 7 on Unix which compares two files.
I am writing code that compares 2 bytes which represent integers. I want to
I'm writing an application, which accesses Excel file with this code: RBTApplication = new
I'm writing some code which could really do with some simple compile time metaprogramming.
I'm writing code in which I use SQL to test several different conditions before
I'm writing a compiler which uses C as an intermediate code which is (Currently)
I'm writing code on the master page, and I need to know which child

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.