code: def pick_item_with_probability(x):
      """This functions picks an item from the collection according to the associated
      probability distribution. The probability estimate of each item in the collection
      is stored in the "probability" field of the particular item. x : a
      collection (list or dictionary) where the values contain a field called probability
      """
      if isinstance(x, dict):
          keylist = list(x.keys())
          keylist.sort()
          random.shuffle(keylist)
          plist = [x[k] for k in keylist]
      else:
          plist = x
      total_p = sum(item.probability for item in plist)
      p = random.uniform(0, total_p)
      accumulate_p = 0
      for item in plist:
          if accumulate_p + item.probability >= p:
              return item
          accumulate_p += item.probability
      assert (
          False
      ), "Shouldn't get here as the accumulated probability should always equal to 1"
  
imports: import argparse, shlex, glob, math, os, random, sys, warnings, copy, imp, ast
label_desc: Use image node_id 3 for calling a global function with example usage: pick_item_with_probability(x) and returns: item