import itertools


def get_pair_template(elements, order_matters=True):
    """Template dictionary used for storing stats.

    Every element-pair is included, even if there are no actual instances.

    Args:
        elements (list of str): doctypes or ideos
        order_matters (bool): if True, the keys are created for each direction of an element-pair.
                              e.g., "foxnews-breitbart" and "breitbart-foxnews" are included separately.
                              if False, only the sorted version ("breitbart-foxnews") is added as a key.

    Returns:
        dict_pairs (dict):
            the dict's keys are 2-item tuples representing doctype pairs
            the dict's values are initialized to 0.

    """

    if order_matters:
        # directional pairs including self-self
        # to exclude self-self: list(itertools.permutations(elements, 2))
        pairs = list(itertools.product(elements, repeat=2))
    else:
        # non-directional pairs including self-self
        # to exclude self-self: list(itertools.combinations(elements, 2))
        pairs = list(itertools.combinations_with_replacement(elements, 2))

    # https://stackoverflow.com/a/2244026
    dict_pairs = {key: 0 for key in pairs}

    return dict_pairs