def strip_hidden(key_tuples, visibilities):
    """Filter each tuple according to visibility.

    Args:
        key_tuples: A sequence of tuples of equal length (i.e. rectangular)
        visibilities: A sequence of booleans equal in length to the tuples contained in key_tuples.

    Returns:
        A sequence equal in length to key_tuples where the items are tuples with a length corresponding
        to the number of items in visibility which are True.
    """
    result = []
    for key_tuple in key_tuples:
        if len(key_tuple) != len(visibilities):
            raise ValueError(
                "length of key tuple {} is not equal to length of visibilities {}".format(
                    key_tuple, visibilities
                )
            )
        filtered_tuple = tuple(item for item, visible in zip(key_tuple, visibilities) if visible)
        result.append(filtered_tuple)
    return result