def expand(table):
    """Flatten and expand the table.

    The original table is a list of tuples, of which the 1st element is a
    value and the second a weight. The resulting table is a list of values,
    where each value appears a number of times defined by its weight.

    :param table: Original table
    :type table: List of (Value, Weight).
    :return: Flattened table
    :rtype: List of values
    """
    t = []
    for r in table:
        for _ in range(r[1]):
            try:
                t.append((r[0], r[2]))
            except IndexError:
                t.append((r[0], None))
    return t