import collections


def _invert_script_to_chars(script_to_chars):
  """Convert script_to_chars to char_to_scripts and return."""
  char_to_scripts = collections.defaultdict(set)
  for script, cps in script_to_chars.items():
    for cp in cps:
      char_to_scripts[cp].add(script)
  return char_to_scripts