<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _confidence(matches, ext=None):
 """ Rough confidence based on string length and file extension"""

    results = []
    for match in matches:
        con = (0.8 if len(match.extension) > 9 else
               float("0.{0}".format(len(match.extension))))
        if ext == match.extension:
            con = 0.9
        results.append(
            PureMagicWithConfidence(confidence=con, **match._asdict()))
    return sorted(results, key=lambda x: x.confidence, reverse=True)