from operator import contains


def is_countable(indices):
    """
    Determines if paths are countable by matrix multiplication when given the indices of
    two different repeated metanode types:

    :param indices: List of Lists, containing the start and end indices of
        visites to metanodes of each type along the metapath in question

    :return: Boolean, returns True, if metanode vists of one type are either separate or contained within
        visits of another type, such that repeated paths can be removed via analysis of the diagonal
        when performaing matrix multiplaction.
    """
    countable = []
    indices = sorted(indices)

    # Countable is eihter no overlap between repeat visits of the same type,
    # or perfect overlap of one within another
    for indices1 in indices[0]:
        for indices2 in indices[1]:
            total = sorted(indices1 + indices2)
            countable.append(contains(indices1, total) or contains(indices2, total))

    return all(countable)