Merging two dic in python3 using Unpacking Generalisations in Python3.5
<p>There are two dictionaries as follow which I want to merge them, my point is to select those keys that I am interested in, for example I am interested in all the keys except county. Solution I 've used is using <code>del</code> function after creating your new dictionary, however I am sure there are more ways that are more efficient to my solution. How can I solve this problem without del function using <strong>UNPACKING ARGUMENT</strong>.</p>

<pre><code>    &gt;&gt;&gt; d1 =  {'avgUserperDay': '12', 'avgPurchaseperDay': '1', 'country': 'Japan'}
    &gt;&gt;&gt; d2 = {'tUser': 1, 'tPurchase': 0, 'country': 'Japan'}
    &gt;&gt;&gt; d ={**d1,**d2}
    &gt;&gt;&gt;{'tUser': 1, 'tPurchase': 0, 'avgPurchaseperDay': '1', 'avgUserperDay': '12', 'country': 'Japan'}
    &gt;&gt;&gt; del d['country']
    &gt;&gt;&gt; d
    {'tUser': 1, 'tPurchase': 0, 'avgPurchaseperDay': '1', 'avgUserperDay': '12'}
</code></pre>

<p>AFTER DISCUSSION, </p>

<p>This command works with 3.5.1,</p>

<pre><code>&gt;&gt;&gt; {**{k:v for k, v in chain(d1.items(), d2.items()) if k != 'country'}}
{'tUser': 1, 'tPurchase': 0, 'avgPurchaseperDay': '1', 'avgUserperDay': '12'}
</code></pre>

<p>why would you want to do it using argument unpacking?
just do:</p>

<pre><code>from itertools import chain
d = {key:value for key, value in chain(d1.iteritems(), d2.iteritems())
     if key not in keys_to_ignore}
</code></pre>

<p>where keys_to_ignore is list/set/tuple of keys you want to ignore</p>

python python-3.5 argument-unpacking