<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def compare_clades(pw):
 """ print min. pident within each clade and then matrix of between-clade max. """

    names = sorted(set([i for i in pw]))
    for i in range(0, 4):
        wi, bt = {}, {}
        for a in names:
            for b in pw[a]:
                if ';' not in a or ';' not in b:
                    continue
                pident = pw[a][b]
                cA, cB = a.split(';')[i], b.split(';')[i]
                if i == 0 and '_' in cA and '_' in cB:
                    cA = cA.rsplit('_', 1)[1]
                    cB = cB.rsplit('_', 1)[1]
                elif '>' in cA or '>' in cB:
                    cA = cA.split('>')[1]
                    cB = cB.split('>')[1]
                if cA == cB:
                    if cA not in wi:
                        wi[cA] = []
                    wi[cA].append(pident)
                else:
                    if cA not in bt:
                        bt[cA] = {}
                    if cB not in bt[cA]:
                        bt[cA][cB] = []
                    bt[cA][cB].append(pident)
        print('\n# min. within')
        for clade, pidents in list(wi.items()):
            print('\t'.join(['wi:%s' % str(i), clade, str(min(pidents))]))
        # print matrix of maximum between groups
        comps = []
        print('\n# max. between')
        for comp in print_pairwise(bt):
            if comp is not None:
                print('\t'.join(['bt:%s' % str(i)] + [str(j) for j in comp]))
                if comp[0] != '#':
                    comps.extend([j for j in comp[1:] if j != '-'])
        print_comps(comps)
        # print matrix of median between groups
        comps = []
        print('\n# median between')
        for comp in print_pairwise(bt, median = True):
            if comp is not None:
                print('\t'.join(['bt:%s' % str(i)] + [str(j) for j in comp]))
                if comp[0] != '#':
                    comps.extend([j for j in comp[1:] if j != '-'])
        print_comps(comps)