code: def take_using_weights(
      items: list[_T], weights: list[int]
  ) -> Generator[_T, None, None]:
      """
      Generator that keeps yielding items from the items list, in proportion to
      their weight. For instance::
  
          # Getting the first 70 items from this generator should have yielded 10
          # times A, 20 times B and 40 times C, all distributed equally..
          take_using_weights(['A', 'B', 'C'], [5, 10, 20])
  
      :param items: List of items to take from.
      :param weights: Integers representing the weight. (Numbers have to be
                      integers, not floats.)
      """
      assert len(items) == len(weights)
      assert len(items) > 0
  
      # Remove items with zero-weight.
      items2 = []
      weights2 = []
      for item, w in zip(items, weights):
          if w > 0:
              items2.append(item)
              weights2.append(w)
  
      items = items2
      weights = weights2
  
      # Make sure that we have some items left.
      if not items:
          raise ValueError(
              "Did't got any items with a positive weight."
          )
  
      #
      already_taken = [0 for i in items]
      item_count = len(items)
      max_weight = max(weights)
  
      i = 0
      while True:
          # Each iteration of this loop, we fill up until by (total_weight/max_weight).
          adding = True
          while adding:
              adding = False
  
              for item_i, item, weight in zip(
                  range(item_count), items, weights
              ):
                  if already_taken[item_i] < i * weight / float(
                      max_weight
                  ):
                      yield item
                      already_taken[item_i] += 1
                      adding = True
  
          i += 1
  
imports: from __future__ import annotations
  import os
  import signal
  import sys
  import threading
  from collections import deque
  from typing import Callable, ContextManager, Dict, Generator, Generic, TypeVar, Union
  from wcwidth import wcwidth
label_desc: Use image node_id 9 for calling a global function with example usage: take_using_weights(items, weights) without return types