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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T07:05:29+00:00 2026-06-11T07:05:29+00:00

I edited it. I made them lists to dictionaries. If a and b are

  • 0

I edited it. I made them lists to dictionaries. If a and b are 2 dictionaries:

a = {'UK':'http://www.uk.com', 'COM':['http://www.uk.com','http://www.michaeljackson.com']}



bb = {'Australia': 'http://www.australia.com', 'COM':['http://www.Australia.com', 'http://www.rafaelnadal.com','http://www.rogerfederer.com']}

I want to union them

{'Australia': ['http://www.australia.com'], 'COM': ['http://www.uk.com', 'http://www.michaeljackson.com', 'http://www.Australia.com', 'http://www.rafaelnadal.com', 'http://www.rogerfederer.com'], 'UK': ['http://www.uk.com']}

I want to union them i.e.

**How to do it in Python without overwwriting and replacing any value?**
  • 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-11T07:05:31+00:00Added an answer on June 11, 2026 at 7:05 am

    Consider using a different data structure, such as a dictionary of sets.

    a = [['UK', ['http://www.uk.com']], ['COM', ['http://www.uk.com'],['http://www.michaeljackson.com']]]
    b = [['Australia', ['http://www.australia.com']], ['COM', ['http://www.Australia.com'], ['http://www.rafaelnadal.com'], ['http://www.rogerfederer.com']]]
    
    # convert these to dictionaries with set values
    a = {item[0]:set(s[0] for s in item[1:]) for item in a}
    b = {item[0]:set(s[0] for s in item[1:]) for item in b}
    
    # define a function to update our dictionary-of-sets data structure
    def union_update_setdict(D, *setdicts):
        """Update dictionary D (with `'key':set(value)` items) with items from setdicts.
    
        If a new key is added to D from setdicts, a shallow copy of the value
        is added to D.
        """
        for setdict in setdicts:
            for k,v in setdict.items():
                try:
                    D[k].update(v)
                except KeyError:
                    D[k] = v.copy()
    
    union_update_setdict(a, b)
    
    
    
    # Now let's test that the code works
    
    expected = [['UK', ['http://www.uk.com']], ['COM', ['http://www.uk.com'], ['http://www.michaeljackson.com'], ['http://www.Australia.com'], ['http://www.rafaelnadal.com'], ['http://www.rogerfederer.com']], ['Australia', ['http://www.australia.com']]]
    
    # put the "expected" results in our new data structure for comparison
    expected = {item[0]:set(s[0] for s in item[1:]) for item in expected}
    
    print a
    assert expected == a
    

    If you really need to keep using your terrible data structure, you can convert it back when you are finished:

    terribledatastruct = [[k]+[[item] for item in v] for k,v in a.items()]
    print terribledatastruct
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I followed the guide here http://www.hackido.com/2010/01/installing-git-on-server-ubuntu-or.html but I cannot find the proper way to
i have edited an app and made some changes in it. I want to
I edited an already-made example from the RXTX website. I am new in Java
I made a very simple application to store variables that can be edited onto
Edited: I want to get the actual with of the document with JS. I
Edited with a SSCCE and a workaround I want to programmatically change the location
EDITED FOR BETTER UNDERSTANDING I made a custom control with propertise for some global
Are there any events that will fire if someone edited my custom made application
I have an extranet made with codeigniter that I want to log every users'
Edit: I'm really sorry. I edited the confusing errors I made in my post.

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.