A common problem is how to convert one set of codes from one type to another. For example,
if you are processing the sex of a patient,
you may need to convert M to 0 and F to 1.
The following code fragment uses conditional statements to implement this (remember to correctly indent the statements):
if value[0] == "M":
value = "0"elif value[0] == "F":
value = "1"else:
value = "2"
While this solution is useful for small code sets, conditional statements can become difficult to manage if the code set is large.
For larger code sets, it is easier to use a dictionary to map one code to another. For more information on using
dictionaries to map code sets, see Converting Code Sets Using a Dictionary.