code: def select_key_and_batch(
      iterator_names: Dict[str, str],
      iterator_probs: Dict[str, float],
      iter_dict: Dict[str, Iterator],
      iterators: Dict[str, Iterator],
  ):
      """Helper function for RandomizedBatchSampler and AlternatingRandomizedBatchSampler
      to select a key from iterator_names using iterator_probs and return a batch
      for the selected key using iter_dict and iterators.
      """
      # Select a candidate iterator using the uniform distribtion
      selected_key = np.random.choice(iterator_names, p=iterator_probs)
      try:
          batch = next(iter_dict[selected_key])
      except StopIteration:
          iter_dict[selected_key] = iter(iterators[selected_key])
          batch = next(iter_dict[selected_key])
  
      return selected_key, batch
  
imports: from collections.abc import Iterator
  from typing import Dict, Optional
  import numpy
  from pytext.config.component import Component, ComponentType
label_desc: Use image node_id 1 for calling a global function with example usage: select_key_and_batch(iterator_names, iterator_probs, iter_dict, iterators) and returns: selected_key,  batch