code: def resolve_name(key, vals, debug=False):
      
      max_priority = max([val[2] for val in vals])
      val_count = Counter([val[1] for val in vals if val[2] == max_priority])
      if len(val_count) == 1:
          unanimous = val_count.most_common(1)
          return unanimous[0][0]
  
      for pkey in val_count:
          if pkey in AMBIGUOUS_PREFERENCES:
              others = set(val_count)
              others.remove(pkey)
              if others == others & AMBIGUOUS_PREFERENCES[pkey]:
                  if debug:
                      print("Resolved: {} -> {}".format(key, pkey))
                  return pkey
  
      # In debug mode, show which languages vote for which name
      if debug and max_priority >= 0:
          votes = defaultdict(list)
          for voter, val, prio in vals:
              if prio == max_priority:
                  votes[val].append(voter)
  
          print("{}:".format(key))
          for val, voters in sorted(votes.items()):
              print("\t{}: {}".format(val, ' '.join(voters)))
  
      # Don't use names that remain ambiguous
      return None
docs: Given a name, and a number of possible values it could resolve to,
      find the single value it should resolve to, in the following way:
  
      - Apply the priority order
      - If names with the highest priority all agree, use that name
      - If there is disagreement that can be resolved by AMBIGUOUS_PREFERENCES,
        use that
      - Otherwise, don't resolve the name (and possibly show a debugging message
        when building the data)