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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:39:12+00:00 2026-05-25T14:39:12+00:00

I am new to python..I have two sorted arrays (by key) that I would

  • 0

I am new to python..I have two sorted arrays (by key) that I would like to merge. Both arrays have some common keys and some exist uniquely in one of the arrays. I want to do an outer join.

Array1 = {'key_1': 10, 'key_2': 14,..'key_m': 321}
Array2 = {'key_1': 15, 'key_2': 12..'key_m':2,..'key_n':34}

I want to merge using key_1..key_n..

Array3 = [[key_1',10,15],['key_2':14:12],..]

I don’t have numpy package installed on my computer. Do I need it to merge this array? what is the best way to code this up? Thanks!!!

  • 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-25T14:39:12+00:00Added an answer on May 25, 2026 at 2:39 pm

    How about this?

    #!/usr/bin/env python
    from itertools import chain
    
    dict1 = {'key_1': 10, 'key_2': 14, 'key_m': 321}
    dict2 = {'key_1': 15, 'key_2': 12, 'key_m':2, 'key_n':34}
    
    dict3 = {}
    
    # Go through all keys in both dictionaries
    for key in set(chain(dict1, dict2)):
    
        # Find the key in either dictionary, using an empty
        # string as the default if it is not found.
        dict3[key] = [dict.get(key, "")
                      for dict in (dict1, dict2)]
    
    print(dict3)
    

    Now dict3 has a list of every value from the input arrays.

    Or if you want it in that [[key, value, value], [key, value, value]...] format:

    #!/usr/bin/env python
    from itertools import chain
    
    dict1 = {'key_1': 10, 'key_2': 14, 'key_m': 321}
    dict2 = {'key_1': 15, 'key_2': 12, 'key_m':2, 'key_n':34}
    
    result = [[key] + [dict.get(key, "")
               for dict in (dict1, dict2)]
              for key in set(chain(dict1, dict2))]
    result.sort()
    
    print(result)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have two methods New() and Edit() and another method make() that has some
I want to merge two CSV files that I have read into python using
I'm new to Python. I have a method that begins: def foo(self, list): length
I'm using Python 2.7. I'm rather new to the python langauge. I have two
We are new to the python world and would like to get started a
I have two django sites that use the same database and share some of
I have two lists created in python like so: list1 = [2, 3, 3,
New to python, bear with me. I have two text files, each has a
I'm new to python and have hit a problem with an SQL query I'm
I am really new to Python and I have been looking for an example

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.