def matchTypes(accept_types, have_types):
 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]

def matchTypes ( accept_types , have_types ) : 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 ]
given the result of parsing an accept: header .