def ord_str(sv, dict): v = dict[sv] # 0 or 1 or 2 or . . return str(v) If you want to use some other form of encoding, such as effect coding or orthogonal encoding, you would define a helper function ...