擅长:python、mysql、java
<p>如果您有:</p>
<pre><code>weights = [('apple', 5), ('banana', 9), ('coconut', 14)]
prices = [('apple', 0.99), ('banana', 1.24), ('coconut', 3.20)]
</code></pre>
<p>你可以通过简单的列表理解:</p>
<pre><code>[(fruit, weight, dict(prices)[fruit]) for fruit, weight in weights]
</code></pre>
<p>编辑:对于大型列表可能无效。这应该更好:</p>
<pre><code>prices_dict = dict(prices)
[(fruit, weight, prices_dict[fruit]) for fruit, weight in weights]
</code></pre>