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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:44:28+00:00 2026-06-12T06:44:28+00:00

I have two files that I loaded into Python, and I am trying to

  • 0

I have two files that I loaded into Python, and I am trying to output a list that will display the common values between the two.

The list from the first file looks like this (not full list, just part of it):

    [datetime.datetime(2010, 7, 30, 12, 20, 19, 143000), datetime.datetime(2010, 7, 30, 12, 22, 33, 631000), datetime.datetime(2010, 7, 30, 12, 22, 41, 236000), datetime.datetime(2010, 7, 30, 12, 23, 43, 547000), datetime.datetime(2010, 7, 30, 12, 23, 57, 453000), datetime.datetime(2010, 7, 30, 12, 26, 4, 713000), datetime.datetime(2010, 7, 30, 12, 26, 9, 46000), datetime.datetime(2010, 7, 30, 12, 28, 30, 313000)]

And the second list looks like this (again, not the full list, just part of it):

    [datetime.datetime(2010, 7, 30, 13, 43, 2, 993000), datetime.datetime(2010, 7, 30, 13, 43, 10, 917000), datetime.datetime(2010, 7, 30, 13, 48, 56, 697000), datetime.datetime(2010, 7, 30, 13, 49, 14, 399000), datetime.datetime(2010, 7, 30, 13, 51, 45, 882000), datetime.datetime(2010, 7, 30, 13, 52, 6, 432000), datetime.datetime(2010, 7, 30, 13, 54, 26, 873000), datetime.datetime(2010, 7, 30, 13, 59, 2, 164000), datetime.datetime(2010, 7, 30, 13, 59, 15, 515000), datetime.datetime(2010, 7, 30, 14, 3, 43, 742000), datetime.datetime(2010, 7, 30, 14, 5, 59, 975000), datetime.datetime(2010, 7, 30, 14, 13, 36, 887000), datetime.datetime(2010, 7, 30, 14, 13, 42, 92000)]

And here is what the code looks like:

    for infilelines in text:
        lspl1 = infilelines.split(',')
        cattime = lspl1[2]
        catdate.append(datetime.strptime(lspl1[1]+cattime,'%d/%m/%Y%H:%M:%S.%f'))



    #print catdate


    NNSRCfile = sf.readsrc(NNSRC)
    l1 = NNSRCfile['date']
    l2 = NNSRCfile['time']
    NNSRCfile['datetime2'] = zip(l1,l2)
    #print NNSRCfile['datetime2']


    NNSRCfile['datetimenew'] = [datetime.strptime(i+j,'%m-%d-%Y%H:%M:%S.%f') for i,j in zip(l1,l2)]

    #print NNSRCfile['datetimenew']
    ii = 0
    while ii <= len(catdate):
        try:
            #print NNSRCfile['datetimenew'].index(catdate[ii]), "WE FOUND A MATCH!!!!"
            indices = NNSRCfile['datetimenew'].index(catdate[ii])
        except:
            print "No match."
            #continue
        ii += 1

I am not getting an error, but the script is not working the way I intended it to. I would like a full list of all of the common elements between the two separate lists. I know I didn’t include the full lists in this post, but when I manually look through it, I know there are commonalities between the two.

Any help is 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-06-12T06:44:29+00:00Added an answer on June 12, 2026 at 6:44 am

    I think that a set is in order here. Assuming you’ve parsed your files into the lists, you can do the following:

    intersection = set(list1) & set(list2)
    

    And Bob’s your uncle, you’re done!


    There’s also a method form of the above:

    intersection = set(list1).intersection(list2)
    

    which has the advantage that you don’t need to create 2 sets (only 1). This means you don’t actually need to read both of your files into memory — you can parse/update the set lazily with the second file.

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

Sidebar

Related Questions

I have five SWF files that are loaded into a main SWF. All five
I have two nib files, one that will open at startup and another that
I have two XML files that are generated by another application I have no
I have two text files that contain columnar data of the variety position -
Hi I have two text files that each contain different information about certain structures.The
I have these two simple files that define a C++ class with a tryME
I have two large (~100 GB) text files that must be iterated through simultaneously.
I have two files: master/newsletter1/file.html master/newsletter2/file.html newsletter1/file.html has a lot of new changes that
I have this c# web app that relies heavily on two dll files that
I have a program that compares two files. I ran visual studio analysis 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.