Quickly build large dict in elegant manner
<p>I have a list with size about 30000: <code>['aa', 'bb', 'cc', 'dd', ...]</code>, from this list, I want to build a dict which maps element to index, so the result dict is <code>{'aa': 0, 'bb': 1, 'cc': 2, 'dd': 3, ...}</code>. Here comes my code:</p>

<pre><code>cnt = 0
mp = {}
for name in name_list:
    mp[name] = cnt
    cnt += 1
return mp
</code></pre>

<p>It seems my code is not concise and effective, so how to improve it?</p>

<p>How about using the list index for each item? </p>

<pre><code>mp = {item: name_list.index(item) for item in name_list}
</code></pre>

python