Converting list to dictionary with list elements as index - Python
<p>From <a href="http://stackoverflow.com/questions/7974959/python-create-dict-from-list-and-auto-gen-increment-the-keys-list-is-the-actua">Python: create dict from list and auto-gen/increment the keys (list is the actual key values)?</a>, it's possible to create a <code>dict</code> from a <code>list</code> using <code>enumerate</code> to generate tuples made up of incremental keys and elements in life, i.e.:</p>

<pre><code>&gt;&gt;&gt; x = ['a', 'b', 'c']
&gt;&gt;&gt; list(enumerate(x))
[(0, 'a'), (1, 'b'), (2, 'c')]
&gt;&gt;&gt; dict(enumerate(x))
{0: 'a', 1: 'b', 2: 'c'}
</code></pre>

<p>It is also possible to reverse the key-value by iterating through every key in the <code>dict</code> (assuming that there is a one-to-one mapping between key-value pairs:</p>

<pre><code>&gt;&gt;&gt; x = ['a', 'b', 'c']
&gt;&gt;&gt; d = dict(enumerate(x))
&gt;&gt;&gt; {v:k for k,v in d.items()}
{'a': 0, 'c': 2, 'b': 1}
</code></pre>

<p>Given the input list <code>['a', 'b', 'c']</code>, how can achieve the dictionary where the elements as the key and incremental index as values <strong>without trying to loop an additional time to reverse the dictionary</strong>?</p>

<p>How about simply:</p>

<pre><code>&gt;&gt;&gt; x = ['a', 'b', 'c']
&gt;&gt;&gt; {j:i for i,j in enumerate(x)}
{'a': 0, 'c': 2, 'b': 1}
</code></pre>

python list dictionary