def MergeResultsFromMultipleFiles(results_by_file, info_levels):
  """Merge multiple results to show occurrences in files and range of values.

  Args:
    results_by_file: A dict of check results indexed by file name.
    info_levels: A list of report levels to merge. E.g., ['warning', 'error']

  Returns:
    A dict of check results in the form of:
    {`check_name`: {`file_name`: [lower_bound, upper_bound]}}
  """

  merged = {}
  for filename, results in results_by_file.iteritems():
    if results:
      for check_name, values in results.iteritems():
        bounds = [float('inf'), -float('inf')]
        tracebacks = set()
        # Example `values`:
        #   {'warning', {'count': 100, 'range': [0, 1]}}
        is_set = False
        for field, details in values.iteritems():
          if field in info_levels:
            if 'range' in details:
              bounds[0] = min(bounds[0], details['range'][0])
              bounds[1] = max(bounds[1], details['range'][1])
              is_set = True
            if 'traceback' in details:
              tracebacks.add(details['traceback'])

        report = {}
        if is_set:
          report['range'] = bounds
        if tracebacks:
          report['traceback'] = list(tracebacks)
        if report:
          if check_name not in merged:
            merged[check_name] = {}
          merged[check_name][filename] = report
  return merged