<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def best_hits(self):
 """ returns a dict with query => best mapped position """

        self.quality_sort()

        best_hits = dict((query, next(blines)) for (query, blines) in \
                        groupby(self, lambda x: x.query))

        self.ref_sort()

        return best_hits