code: def weighted_choice(mapping, seed=None):
      """Returns a single element from a weighted sample.
  
      The input is a dictionary of items with weights as values.
      """
      # use roulette method
      rnd = seed.random() * sum(mapping.values())
      for k, w in mapping.items():
          rnd -= w
          if rnd < 0:
              return k
  
file_path: networkx/networkx/utils/random_sequence.py
imports: import networkx
  from networkx.utils import py_random_state
label_desc: Use image node_id 6 for calling a global function with example usage: weighted_choice(mapping, seed) and returns: k