code: def sort_matches(matches):
      '''Sorts a ``list`` of matches best to worst'''
      multipliers = {'exact':10**5,'fname':10**4,'fuzzy':10**2,'fuzzy_fragment':1}
      matches = [(multipliers[x.type]*(x.amount if x.amount else 1),x) for x in matches]
      return [x[1] for x in sorted(matches,reverse=True)]