code: def expand_dict_as_keys(d):
      
      to_product = []
      for key, values in sorted(d.items()):
          # if we sort the inputs here, itertools.product will keep a stable sort order for us later
          key_values = sorted([(key, v) for v in utils.ensure_listable(values) if v is not None])
          if key_values:
              to_product.append(key_values)
      return list(itertools.product(*to_product))
docs: Expands a dictionary into a list of immutables with cartesian product
  
      :param d: dictionary (of strings or lists)
      :returns: cartesian product of list parts