code: def _join_safety_ratings_lists(
      safety_ratings_lists: Iterable[list[glm.SafetyRating]],
  ):
      ratings = {}
      blocked = collections.defaultdict(list)
  
      for safety_ratings_list in safety_ratings_lists:
          for rating in safety_ratings_list:
              ratings[rating.category] = rating.probability
              blocked[rating.category].append(rating.blocked)
  
      blocked = {
          category: any(blocked)
          for category, blocked in blocked.items()
      }
  
      safety_list = []
      for (category, probability), blocked in zip(
          ratings.items(), blocked.values()
      ):
          safety_list.append(
              glm.SafetyRating(
                  category=category,
                  probability=probability,
                  blocked=blocked,
              )
          )
  
      return safety_list
  
imports: from __future__ import annotations
  import collections
  import contextlib
  import sys
  from collections.abc import Iterable, AsyncIterable
  import dataclasses
  import itertools
  import textwrap
  from typing import TypedDict, Union
  import google.protobuf.json_format
  import google.api_core.exceptions
  from google.ai import generativelanguage
  from google.generativeai import string_utils
label_desc: Use image node_id 3 for calling a global function with example usage: _join_safety_ratings_lists(safety_ratings_lists) and returns: safety_list