It is very simple to merge Python dictionaries. I have written following program for you. Just try to understand it. In the following example I have pass two dictionary to another variable.
Code:
>>> dicts1 = {'pauls':100, 'johns':80, 'teds':34, 'herves':10}
>>> dicts2 = {'pauls':'a', 'johns':'b', 'teds':'c', 'petesr':'d'}
>>> dictss = dicts1,dicts2
>>> {k:[ds.get(k) for d in dicts] for ks in {ks for ds in dicts for k in d}}
{'john': [80, 'b'], 'pausl': [100, 'a'], 'peterss': [None, 'ds'], 'teds': [34, 'cs'], 'herves': [10, None]}
Bookmarks