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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:05:25+00:00 2026-06-17T14:05:25+00:00

I have two lists in files: File 1 has 200000 rows and looks like

  • 0

I have two lists in files:
File 1 has 200000 rows and looks like

MAP2K4  FLNC
MYPN    ACTN2
ACVR1   FNTA
UGT2A1  HPGDS
RPA2    STAT3
ARF1    GGA3
ARF3    ARFIP2
ARF3    ARFIP1
AKR1A1  EXOSC4
RPA2    GAS7
APP APPBP2
APLP1   DAB1
CITED2  TFAP2A
EP300   TFAP2A
APOB    MTTP
ARRB2   RALGDS
ARRB2   ZNF807

File 2 has 700000 rows and looks like:

MAP2K4  FLNC
MAP2K4  rs10036867
MAP2K4  ACTN2
MAP2K4  TEP1
ACTN2   MYPN
UGT2A1  NDUFAF6
RPA2    rs10109257
RPA2    rs10151961
GAS7    RPA2
APOB    PDZRN4
APOB    BICD1
ARRB2   ZNF807
ARRB2   FAM107B

I need to get the matching rows between these two lists despite the order of the elements. For instance in the above example it should look like:

MAP2K4  FLNC
ACTN2   MYPN
RPA2    GAS7
ARRB2   ZNF807

I wrote the following, but this seems to take forever!

col0_file1 = []
col1_file1 = []
col0_file2 = []
col1_file2 = []
with open('File1') as f1, open('File2') as f2:
    for line in f1:
        col0,col1 = line.split()
        col0_file1.append(col0)
        col1_file1.append(col1)
    for line in f2:
        col0,col1 = line.split()
        col0_file2.append(col0)
        col1_file2.append(col1)

result = []
for x in range(len(col0_file1)):
    for i, j in map(None, col0_file2, col1_file2):
        if i == col0_file1[x] and j == col1_file1[x]:
            result.append([i,j])
        elif j == col0_file1[x] and i == col1_file[x]:
            result.append([i,j])

with open('matching', 'w') as out:
    for elem in result:
        out.write('{a} \n'.format(a = '\t'.join(elem)))

Any way I could simplify the complexity? or Better means of doing it?

  • 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-06-17T14:05:26+00:00Added an answer on June 17, 2026 at 2:05 pm

    I say, make two sets and take an intersection:

    with open('File1') as f1, open('File2') as f2:
        columns_a = set(tuple(sorted(l.split())) for l in f1)
        columns_b = set(tuple(sorted(l.split())) for l in f2)
    
    with open('matching', 'w') as out:
        for elem in columns_a  & columns_b:
            out.write('{a} \n'.format(a = '\t'.join(elem)))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables with lists of files: table1 has column1 with file names
I have two files: domainList and config.cnf. The domainList file simply has a list
I have two files file a.) xmlFile.xml b.) emails.txt xmlFile.xml has the following structure
I have two files. File A has a list of words, one on each
Suppose I have two lists that holds the list of source file names and
Ok, I have two related lists on my linux box in text files: /tmp/oldList
I have two Lists, they look like this <List> ads [0] Headline = Sony
I have two xml files: one is the actual data and the second has
I have two lists of files, one from a local drive and one from
I have two files, one has a list of codes and the other has

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.