There are better (and more "pythonic") ways to do what you want.
Use either a tuple (or a list if you need to change it), where the order will be saved:
code_lookup = ('PL', 'DE', 'FR') return lookup.index('PL')
Or use the dictionary line by line:
code_lookup = {'PL':0, 'FR':2, 'DE':3} return code_lookup['PL']
The latter is preferable, in my opinion, more readable and explicit.
A namedtuple may also be useful, in your particular case, although it probably overflows:
import collections Nationalities = collections.namedtuple('Nationalities', ['Poland', 'France', 'Germany']) nat = Nationalities('PL', 'FR', 'DE') print nat.Poland print nat.index(nat.Germany)
source share