import itertools


def common_age(a, b):
    """
    Calculates the number of ages in common between two lists of ages.
    Allows for ages to be one year apart.

    Parameters
    ----------
    a: list
        list of age strings to be compared to b
    b: list
        list of age strings to be compared to a

    Raises
    ------
    TypeError
        if a or b are not lists

    Returns
    -------
    integer
        number of ages in common

    Example
    --------
    >>> list_1 = ['15', '20', '2']
    >>> list_2 = ['15', '15', '20', '2', '99']
    >>> common_age(list_1, list_2)
    4
    """
    # Check variable types
    if not ((isinstance(a, list)) and (isinstance(b, list))):
        raise TypeError('Both variables being compared must contain lists')

    # Compare two age sets against each other
    comparisons = list(itertools.product(a, b))

    # Count how many are equal or 1 year apart
    value = [abs(int(x)-int(y)) for x, y in comparisons]
    value = len(list(filter(lambda x: x <= 1, value)))

    return value