import itertools


def _get_common_blocks(dp_block_sizes, dp_ids):
    """Return all pairs of non-empty blocks across dataproviders.

    :returns
        dict mapping block identifier to a list of all combinations of
        data provider pairs containing this block.

        block_id -> List(pairs of dp ids)
        e.g. {'1': [(26, 27), (26, 28), (27, 28)]}
    """
    blocks = {}
    for dp1, dp2 in itertools.combinations(dp_ids, 2):
        # Get the intersection of blocks between these two dataproviders
        common_block_ids = set(dp_block_sizes[dp1]).intersection(set(dp_block_sizes[dp2]))
        for block_id in common_block_ids:
            blocks.setdefault(block_id, []).append((dp1, dp2))
    return blocks