擅长:python、mysql、java
<p>为什么不做<code>dict</code>列表理解:</p>
<pre><code>>>> dict([i.values() for i in options_d])
{36: 'Angular', 37: 'Java', 38: 'PHP', 39: 'Python', 40: 'C#', 41: 'C', 42: '.NET', 43: 'Ruby', 44: 'Rails', 45: 'OS-Linux', 55: 'Maschinenbau', 56: 'Automotive', 57: 'Engineering'}
>>>
</code></pre>
<p>或对于较低版本(字典无序时):</p>
<pre><code>>>> dict([list(i.values())[::-1] for i in options_d])
{36: 'Angular', 37: 'Java', 38: 'PHP', 39: 'Python', 40: 'C#', 41: 'C', 42: '.NET', 43: 'Ruby', 44: 'Rails', 45: 'OS-Linux', 55: 'Maschinenbau', 56: 'Automotive', 57: 'Engineering'}
>>>
</code></pre>
<p>它简单地遍历字典列表,得到字典的值,然后有一个外部的<code>dict(...)</code>使它成为字典,所以实际上,奇数索引值将是键,偶数索引值将是值。你知道吗</p>