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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:55:22+00:00 2026-06-18T06:55:22+00:00

here is a scenario, I am checking if elements of A are present in

  • 0

here is a scenario, I am checking if elements of A are present in B. while this code works, it takes a lot of time when I read through million of lines. The efficient way would be to make each list in A and B as dictionary and look if they are present in each other. But I am not able to think of a simple way to do dictionary lookup. That is for each key-value pair in dict A, I want to check if that key-value pair is present in dictB

A = [['A',[1,2,3]],['D',[3,4]],['E',[6,7]]]

B=  [['A',[1,2,3]],['E',[6,7]],['F',[8,9]]]

count = 0

for line in A:

  if len(line[1]) > 1:

     if line in B:

       count = count + 1

print count
  • 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-18T06:55:23+00:00Added an answer on June 18, 2026 at 6:55 am
    1. convert the lists to tuples
    2. convert the list of tuples to a set
    3. intersect the two sets
    4. print the length of the intersection

    Example:

    A = [['A',[1,2,3]],['D',[3,4]],['E',[6,7]]] 
    B = [['A',[1,2,3]],['E',[6,7]],['F',[8,9]]]
    
    A_set = set((a, tuple(b)) for a, b in A)
    B_set = set((a, tuple(b)) for a, b in B)
    print len(A_set & B_set)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a strange scenario here. I have this code: // For checking if
Here the scenario : A method is called each minute by a timer. This
Am just wondering how to workaround my scenario,here is my code try { bool
I referred to this somewhat similar question . However here the scenario is different:
Can someone please help? Here is my jQuery. The scenario is this, I have
I know how to write tab host,but here the scenario is little bit different
Here is the scenario. I'm writing my geo-ruby oracle adapter for Ruby On Rails
Here's the scenario: In production, I want to send and receive sms messages. In
Here's the scenario. As a creator of publicly licensed, open source APIs, my group
Here is my scenario: I have two MySQL tables: Categories (columns: id, category) Items

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.