I'm trying to count up ip addresses found in a log file on two servers and then merge the dictionary stats together without loosing elements or counts. I found a partial solution in another stack overflow question but as you can see it drops the '10.10.0.1':7
pair.
>>> a = {'192.168.1.21':23,'127.0.0.1':5,'12.12.12.12':5,'55.55.55.55':10}
>>> b = {'192.168.1.21':27,'10.10.0.1':7,'127.0.0.1':1}
>>> c = {}
>>> for elem in a:
... c[elem] = b.get(elem, 0) + a[elem]
...
>>> print c
{'55.55.55.55': 10, '12.12.12.12': 5, '127.0.0.1': 6, '192.168.1.21': 50}
The counts are being added together but if the key doesn't exist in dict a, it gets dropped. I'm having trouble figuring out the last bit of logic... perhaps another for elem in b: if a.get(elem, 0) exists: pass else add it to c?