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()
forond? that defeats the whole purpose of hash. do aprint dir({})in python shell, understand what every method does. pls try something and post your work. - tuxuday