Defining and referring in one move initially confused me, I would have defined kept the two separate for clarity.
i.e.
```Python
stat_code = {'mean': 0, 'sum': 1, 'maximum': 2, 'minimum': 3, 'standard_deviation': 6}
...
gribapi.grib_set_long(grib, "typeOfStatisticalProcessing",
                      stat_code[cell_method.method])
```