def normalize_language_tag(tag):
 tag = ascii_lower(tag).replace(u'_', u'-')
 tag = re.sub(u'-([a-zA-Z0-9])-', u'-\\1_', tag)
 subtags = [subtag.replace(u'_', u'-') for subtag in tag.split(u'-')]
 base_tag = (subtags.pop(0),)
 taglist = {base_tag[0]}
 for n in range(len(subtags), 0, (-1)):
  for tags in itertools.combinations(subtags, n):
   taglist.add(u'-'.join((base_tag + tags)))
 return taglist

def normalize_language_tag ( tag ) : tag = ascii_lower ( tag ) . replace ( u'_' , u'-' ) tag = re . sub ( u'-([a-zA-Z0-9])-' , u'-\\1_' , tag ) subtags = [ subtag . replace ( u'_' , u'-' ) for subtag in tag . split ( u'-' ) ] base_tag = ( subtags . pop ( 0 ) , ) taglist = { base_tag [ 0 ] } for n in range ( len ( subtags ) , 0 , ( - 1 ) ) : for tags in itertools . combinations ( subtags , n ) : taglist . add ( u'-' . join ( ( base_tag + tags ) ) ) return taglist
return a list of normalized combinations for a bcp 47 language tag .