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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:34:16+00:00 2026-05-27T18:34:16+00:00

I have two large dictionaries with unique keys but possibly overlapping values. I want

  • 0

I have two large dictionaries with unique keys but possibly overlapping values. I want to compare each set of dictionary values against each other and find the number of overlaps. I have done this using two for loops and set but am wondering if there is a faster/more elegant way to do this.

dic1 = {'a': ['1','2','3'], 'b':['4','5','6'], 'c':['7','8','9']}
dic2 = {'d': ['1','8','9'], 'e':['10','11','12'], 'f':['7','8','9']}

final_list=[]
for key1  in dic1:
    temp=[]    
    for key2 in dic2:
        test  = set(dic1[key1])
        query = set(dic2[key2])
        x = len(test & query)
        temp.append( [key2, x] )
    final_list.append([key1, temp])
  • 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-27T18:34:17+00:00Added an answer on May 27, 2026 at 6:34 pm

    You want to “invert” one (or both) of your dictionaries.

    val1 = defaultdict(list)
    for k in dic1:
        for v in dic1[k]:
            val[v].append( k )
    # val1 is a dictionary with each value mapped to the list of keys that contain that value.
    
    for k in dic2: 
        for v in dic2[k]:
            val1[v] is the list of all keys in dic1 that have this value
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have two large (text) files which are allegedly identical, but I want
Here's my problem: Lets say I have two dictionaries, dict_a and dict_b. Each of
I have two large MySQL databases with identical schemas that I want to merge.
I have two tables: Dictionary, Names. Both tables have large number of rows (like
I have two very large lists. They both were originally in excel, but the
I have two non-negative longs. They may be large, close to Long.MAX_VALUE. I want
I have two large XML files(c.100MB) containing a number of items. I want to
I have two hash tables in the form of dictionaries. The keys map features
I have the following 2 dictionaries, d1={aa:[1,2,3],bb:[4,5,6],cc:[7,8,9]} d2={aa:[1,2,3],bb:[1,1,1,1,1,1],cc:[7,8]} How could I compare these two
I have two large tables and want to combine all of the column names

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.