I have a list with size about 30000: ['aa', 'bb', 'cc', 'dd', ...]
, from this list, I want to build a dict which maps element to index, so the result dict is {'aa': 0, 'bb': 1, 'cc': 2, 'dd': 3, ...}
. Here comes my code:
cnt = 0
mp = {}
for name in name_list:
mp[name] = cnt
cnt += 1
return mp
It seems my code is not concise and effective, so how to improve it?