def count_leaves(x):
    """
    Return the number of non-sequence items in a given recursive sequence.
    """
    if hasattr(x, 'keys'):
        x = list(x.values())
    if hasattr(x, '__getitem__'):
        return sum(map(count_leaves, x))

    return 1
Return the number of non-sequence items in a given recursive sequence.