def _product(*args):
    """Returns a Cartesian product of provided `*args`.

    The result is the same as the list of lists produced by nested loops going
    through every passed collection:

        result = []
        for x in arg1:
            for y in arg2:
                ...
                    return result.append([x, y, ...])

    For example, for [['a', 'b'], [1, 2]] the function will return
    [['a', 1], ['a', 2], ['b', 1] ['b', 2]].

    Note that unlike Python's `itertools.product` the result is a list and as
    such an entire result is materialized in memory, so clients should use
    this method with care to avoid excessive memory usage.

    Another difference with Python's implementation is that instead of tuples
    Cartesian coordinates are returned as lists instead of tuples for
    efficiency reasons.

    Args:
      *args: iterable instances (dimensions) of a certesian product

    Returns:
      Cartesian product of provided arguments.
    """
    product = [[]]

    for arg in args:
        product = [p + [e] for p in product for e in arg]

    return product