def order_by_precedence(media_type_lst):
 ret = [set(), set(), set(), set()]
 for media_type in media_type_lst:
  precedence = _MediaType(media_type).precedence
  ret[(3 - precedence)].add(media_type)
 return [media_types for media_types in ret if media_types]

def order_by_precedence ( media_type_lst ) : ret = [ set ( ) , set ( ) , set ( ) , set ( ) ] for media_type in media_type_lst : precedence = _MediaType ( media_type ) . precedence ret [ ( 3 - precedence ) ] . add ( media_type ) return [ media_types for media_types in ret if media_types ]
returns a list of sets of media type strings .