Try this, it works in Python 2.6 and later:
from string import ascii_lowercase d = {} for i, c in enumerate(ascii_lowercase, 1): d[c] = i
If you are using Python 2.7 or later, you can use dictionary understanding:
d = {c : i for i, c in enumerate(ascii_lowercase, 1)}
รscar Lรณpez
source share