def best_match(supported, header):
 parsed_header = [parse_media_range(r) for r in _filter_blank(header.split(','))]
 weighted_matches = []
 pos = 0
 for mime_type in supported:
  weighted_matches.append((fitness_and_quality_parsed(mime_type, parsed_header), pos, mime_type))
  pos += 1
 weighted_matches.sort()
 return ((weighted_matches[(-1)][0][1] and weighted_matches[(-1)][2]) or '')

def best_match ( supported , header ) : parsed_header = [ parse_media_range ( r ) for r in _filter_blank ( header . split ( ',' ) ) ] weighted_matches = [ ] pos = 0 for mime_type in supported : weighted_matches . append ( ( fitness_and_quality_parsed ( mime_type , parsed_header ) , pos , mime_type ) ) pos += 1 weighted_matches . sort ( ) return ( ( weighted_matches [ ( - 1 ) ] [ 0 ] [ 1 ] and weighted_matches [ ( - 1 ) ] [ 2 ] ) or '' )
takes a list of supported mime-types and finds the best match for all the media-ranges listed in header .