def best_match(names, i):
    """
    Find matches starting from index i.
    Matches have to be at least 3 letters, otherwise it's a mess for big sets.
    Go with largest set of matches instead of longer matches.
    Return (number of matches, matching chars)
    """
    matchlen = 3
    nmatches = 1
    while (i+nmatches < len(names) and names[i+nmatches][:matchlen] ==
            names[i][:matchlen]):
        nmatches += 1
    while matchlen < 8 and all([names[i+j][:matchlen+1] ==
        names[i][:matchlen+1] for j in range(1,nmatches)]):
        matchlen += 1
    return nmatches, names[i][:matchlen]