def matchTypes(accept_types, have_types):
    """Given the result of parsing an Accept: header, and the
    available MIME types, return the acceptable types with their
    quality markdowns.

    For example:

    >>> acceptable = parseAcceptHeader('text/html, text/plain; q=0.5')
    >>> matchTypes(acceptable, ['text/plain', 'text/html', 'image/jpeg'])
    [('text/html', 1.0), ('text/plain', 0.5)]


    Type signature: ([(str, str, float)], [str]) -> [(str, float)]
    """
    if not accept_types:
        default = 1
    else:
        default = 0
    match_main = {}
    match_sub = {}
    for main, sub, q in accept_types:
        if main == '*':
            default = max(default, q)
            continue
        elif sub == '*':
            match_main[main] = max(match_main.get(main, 0), q)
        else:
            match_sub[main, sub] = max(match_sub.get((main, sub), 0), q)
    accepted_list = []
    order_maintainer = 0
    for mtype in have_types:
        main, sub = mtype.split('/')
        if (main, sub) in match_sub:
            q = match_sub[main, sub]
        else:
            q = match_main.get(main, default)
        if q:
            accepted_list.append((1 - q, order_maintainer, q, mtype))
            order_maintainer += 1
    accepted_list.sort()
    return [(mtype, q) for _, _, q, mtype in accepted_list]
