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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:13:38+00:00 2026-06-12T12:13:38+00:00

I am trying to update some values of a large dictionary using values from

  • 0

I am trying to update some values of a large dictionary using values from another dictionary where they have similar keys (the same date but in a different format). The process I’m currently using is too slow and I want to reduce the bottleneck.

This is my current solution (it writes the updated dict to a file):

from dateutil import parser
File = open(r'E:Test1.txt','w')

b = {'1946-1-1':0,..........,'2012-12-31':5}
d = {'1952-12-12':5,........,'1994-7-2':10}

for key1, val1 in b.items():
    DateK1 = parser.parse(key1)
    Value = val1
    for key2, val2 in d.items():
        DateK2 = parser.parse(key2)
        if DateK1 == DateK2:
            d[key2] = Value        

Order= sorted(d.items(), key=lambda t: t[0])

for item in Order:
    File.write('%s,%s\n' % item)
File.close()
  • 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-12T12:13:39+00:00Added an answer on June 12, 2026 at 12:13 pm

    You should use the update method to merge dictionaries:

    b.update(d)
    

    .

    At the moment you are iterating over d for every key in b… which is slow. You can get around this by setting up two dictionaries which will have matching keys (and equal dates will hash the same – perhaps the cool thing to note here is that datetime objects hash):

    b1 = dict( (parser.parse(k),v) for k,v for b.iteritems() )
    d1 = dict( (parser.parse(k),v) for k,v for d.iteritems() )
    
    d1.update(b1) # update d1 with the values from b1
    

    Edit:

    I’ve just realised that you’re not quite doing an update, since only those shared values are being updated, so instead (again by just iterating once):

    for k_d1 in d1:
        if k_d1 in b1:
            d1[k_d1] = b1[k_d1]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i'm trying to make a ajax update in prototype with some values from a
Hi I am trying to update a div with some html from another div.
I'm trying to update the display brightness from a widget but i have some
Hit a speed bump, trying to update some column values in my table from
I have a strange problem. I am trying to update some fields using linq
I'm trying to update some properties with KVC. The properties have been synthesized. This
Hi I am trying to make some update using osql.exe against a sql file
I have a xml file that changed when i update some values, and i'm
I'm trying update some values for some hidden input boxes, but I'm not very
I am trying to get some values from the following line... $txt = 'Auction

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.