def contains_at_depth(haystack, needle, n):
    # Specifically use hasattr rather than isinstance(..., collections.Iterable)
    # because we want to include lists but reject strings.
    if not hasattr(haystack, '__iter__'):
        return False
    if n == 0:
        return needle in haystack
    else:
        for item in haystack:
            if contains_at_depth(item, needle, n - 1):
                return True
        return False
Is the needle in haystack at depth n?
dataset/ETHPy150Open letsencrypt/letsencrypt/certbot-nginx/certbot_nginx/tests/util.py/contains_at_depth