def summarizekeys(d, counts={}, base=''):
    """Summarizes keys in the given dict, recursively.
    This means counting how many fields exist at each level.
    Returns keys of the form ``key0.key1`` and values of ints.
    Checks if `d` is instance of dict before doing anything.
    """
    if not isinstance(d, dict): return counts
    for k, v in d.items():
        k = '.'.join((base, k)) if base else k
        if k not in counts:
            counts[k] = 0
        counts[k] += 1
        summarizekeys(v, counts=counts, base=k)
    return counts