def purity(first_clustering, second_clustering):
    """
    Returns the purity of the given two clusterings

    :param first_clusterings: a set of iterables to compare
    :param second_clusterings: a set of iterables to compare

    :return: the purity index as a double
    """
    summation = 0

    for cluster in first_clustering:
        highest = 0
        for comparer in second_clustering:
            next_element = len(cluster.intersection(comparer))
            if next_element > highest:
                highest = next_element

        summation += highest

    # find total number of data points
    N = sum(len(cluster) for cluster in first_clustering)

    if N == 0:
        return 0

    return summation / N