def DictProduct(dictionary):
  """Computes a cartesian product of dict with iterable values.

  This utility function, accepts a dictionary with iterable values, computes
  cartesian products of these values and yields dictionaries of expanded values.

  Examples:
    >>> list(DictProduct({"a": [1, 2], "b": [3, 4]}))
    [{"a": 1, "b": 3}, {"a": 1, "b": 4}, {"a": 2, "b": 3}, {"a": 2, "b": 4}]

  Args:
    dictionary: A dictionary with iterable values.

  Yields:
    Dictionaries with values being a result of cartesian product of values of
    the input dictionary.
  """
  keys, values = Unzip(iteritems(dictionary))
  for product_values in itertools.product(*values):
    yield dict(zip(keys, product_values))
Computes a cartesian product of dict with iterable values.

  This utility function, accepts a dictionary with iterable values, computes
  cartesian products of these values and yields dictionaries of expanded values.

  Examples:
    >>> list(DictProduct({"a": [1, 2], "b": [3, 4]}))
    [{"a": 1, "b": 3}, {"a": 1, "b": 4}, {"a": 2, "b": 3}, {"a": 2, "b": 4}]

  Args:
    dictionary: A dictionary with iterable values.

  Yields:
    Dictionaries with values being a result of cartesian product of values of
    the input dictionary.