code: def __init__(
      self, collection: Union[Dict, List], key: Union[int, str]
  ) -> None:
      if not isinstance(collection, (dict, list)):
          raise TypeError(
              f"Input type is expected to be a mapping or list, but got {type(collection)} "
              f"for input key '{key}'."
          )
      if isinstance(collection, list) and isinstance(key, str):
          raise ValueError(
              "Key should be int for collection of type list"
          )
  
      self.collection = collection
      self.key = key
  
imports: import collections.abc
  import functools
  import hashlib
  import logging
  import random
  import shutil
  import warnings
  from pathlib import Path
  from typing import Any, Callable, cast, Dict, List, Optional, TextIO, Tuple, Type, TypeVar, Union
  import torch
label_desc: Use image node_id 1 to create a new _CollectionItem object  with example: obj = _CollectionItem(collection, key)