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

  • Home
  • SEARCH
  • 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 8244429
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T21:50:56+00:00 2026-06-07T21:50:56+00:00

I have 2 dictionaries with the same keys: d={123:’bla’, 456: blabla} e={123:’bla’, 456:”} Dictionary

  • 0

I have 2 dictionaries with the same keys:

d={123:'bla', 456: blabla}
e={123:'bla', 456:''}

Dictionary e has some empty values and if this is the case and the IDs are the same I’d like to replace the empty value with the value from d.

I am looking for something like this:

if d.keys()==e.keys():
    e.values==d.values()
print e

However, I couldn’t find anything in the Python documentation that compares single keys and updates the values.

Can someone help or point me at something?

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-06-07T21:50:57+00:00Added an answer on June 7, 2026 at 9:50 pm

    You can do a straight update if you don’t mind overwriting differing values with

    e.update(d)
    

    or if you want to make sure you only overwrite the ones containing empty values then you will need to iterate over your dictionary to find them, and update selectively

    # Python 2.x
    for key, value in e.iteritems():
        if value == '':
            e[key] = d.get(key)
    
    # Python 3.x
    for key, value in e.items():
        if value == '':
            e[key] = d.get(key)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There are two dictionaries like this, two dictionaries have same keys but different values.
I have two generic Dictionaries. Both have the same keys, but their values can
Possible Duplicate: Python dictionary, keep keys/values in same order as declared If I have
I have an NSArray of NSDictionaries where each dictionary has the same keys. I
I have 2 lists, both of which contain same number of dictionaries. Each dictionary
I have two dictionaries with the same structure: Dictionary<string, int> foo = new Dictionary<string,
I have an NSArray storing NSDictionaries. Each dictionary has two keys; a name and
I have a list of dictionaries that have the same keys within eg: [{k1:'foo',
I have a dictionary of keys and values, for example: { fred: 1, dave:
I have a List of Dictionaries that have keys of type string and values

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.