def _create_script_to_default_lang(lang_script_data):
  """Iterates over all the scripts in lang_script_data, and returns a map
  from each script to the default language code, generally based on cldr
  likely subtag data.  This assigns 'en' to Latn by fiat (cldr defaults to
  'und').  Some other scripts (e.g. Dsrt) just get 'und'.

  This checks that the default lang for a script actually uses that script
  in lang_script_data, when the default lang is not 'und'.
  """

  script_to_default_lang = {}
  all_scripts = set()
  script_to_used = collections.defaultdict(set)
  script_to_unused = collections.defaultdict(set)
  for lang in lang_script_data:
    used, unused = lang_script_data[lang]
    all_scripts |= used
    all_scripts |= unused
    for script in used:
      script_to_used[script].add(lang)
    for script in unused:
      script_to_unused[script].add(lang)

  # Add scripts without langs.
  all_scripts.add('Zsym')
  all_scripts.add('Zsye')

  # Patch Klingon as default lang for (unused) script pIqaD
  script_to_used['Piqd'].add('tlh')

  for script in sorted(all_scripts):
    default_lang = cldr_data.get_likely_subtags('und-' + script)[0]

    if default_lang == 'und':
      if script == 'Latn':
        default_lang = 'en' # cultural bias...
      else:
        _log('no default lang for script %s' % script)
        langs = script_to_used[script]
        if langs:
          default_lang = iter(langs).next()
          _log((default_lang, langs) % 'using used lang %s from %s')
        else:
          langs = script_to_unused[script]
          if langs:
            default_lang = iter(langs).next()
            _log('using unused lang %s from %s' % (default_lang, langs))
          else:
            _log('defaulting to \'und\'')
    else:
      used, unused = lang_script_data[default_lang]
      assert script in used or script in unused

    script_to_default_lang[script] = default_lang

  return script_to_default_lang
dataset/ETHPy150Open googlei18n/nototools/nototools/lang_data.py/_create_script_to_default_lang/swapped operands of `%`