擅长:python、mysql、java
<p>一颗美丽的宝石在<a href="https://stackoverflow.com/questions/1551666/how-can-2-python-dictionaries-become-1/1551878#1551878">this closed question</a>:</p>
<p>“单行道”改变了两个输入指令</p>
<pre><code>basket = dict(basket_one, **basket_two)
</code></pre>
<p>学习什么<a href="http://www.saltycrane.com/blog/2008/01/how-to-use-args-and-kwargs-in-python/" rel="noreferrer">^{<cd1>} (the ^{<cd2>}) means here</a>。</p>
<p>如果发生冲突,来自<code>basket_two</code>的项将覆盖来自<code>basket_one</code>的项。作为一行代码,这是非常可读和透明的,我不后悔使用它任何时候,一个dict,这是一个混合了其他两个有用的(任何读者谁有困难理解它将实际上是非常好的服务方式,这促使他或她学习<code>dict</code>和<code>**</code>的形式;-)。例如,使用如下:</p>
<pre><code>x = mungesomedict(dict(adict, **anotherdict))
</code></pre>
<p>在我的代码中经常出现。</p>
<p>最初由<a href="https://stackoverflow.com/users/95810/alex-martelli">Alex Martelli</a>提交</p>
<p><strong><em>注意:</em>在Python 3中,只有basket 2中的每个键都是<code>string</code>时,这才有效。</strong></p>