<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def buildfitfcn(self):
 """ Create fit function to fit models in list ``models``. """

        def _fitfcn(p, flatmodels=self.flatmodels):
            ans = gvar.BufferDict()
            for m in flatmodels:
                ans[m.datatag] = (
                    m.fitfcn(p) if m.ncg <= 1 else
                    MultiFitter.coarse_grain(m.fitfcn(p), m.ncg)
                    )
            return ans
        return _fitfcn