code: def group_stats(stats: List[CacheStat]) -> List[CacheStat]:
      """Group a list of CacheStats by category_name and cache_name and sum byte_length"""
  
      def key_function(individual_stat):
          return (
              individual_stat.category_name,
              individual_stat.cache_name,
          )
  
      result: List[CacheStat] = []
  
      sorted_stats = sorted(stats, key=key_function)
      grouped_stats = itertools.groupby(sorted_stats, key=key_function)
  
      for (
          category_name,
          cache_name,
      ), single_group_stats in grouped_stats:
          result.append(
              CacheStat(
                  category_name=category_name,
                  cache_name=cache_name,
                  byte_length=sum(
                      map(
                          lambda item: item.byte_length,
                          single_group_stats,
                      )
                  ),
              )
          )
      return result
  
file_path: streamlit/lib/streamlit/runtime/stats.py
imports: import itertools
  from abc import abstractmethod
  from typing import List, NamedTuple
  from typing_extensions import Protocol, runtime_checkable
  from streamlit.proto.openmetrics_data_model_pb2 import Metric
label_desc: Use image node_id 1 for calling a global function with example usage: group_stats(stats) and returns: result, individual_stat,  individual_stat